2016-04-29 86 views
-1

我刚学的代码使用MVS,看 “https://www.youtube.com/watch?v=f0WuJGhFhlU这个C++代码是怎么回事?

下面的代码...

#include "stdafx.h" 
#include <iostream> 
#include <string> 
#include <string.h> 
#include <cstring> 

using namespace std; 

int main(); 
{ 
    //Get seed colour 
    string seedColour = ""; //The empty "" is what "seedColor" will be chaned to after cin. 
    cout << "Enter Seed Colour (Red/Blue?) \n"; 
    cin >> seedColour; //The user will iunput the seed's colour, which will change the empty "" and we now have (eg) "string seedColour = "red"" 

    //Get Temp 
    int temp = 0; 
     cout << "Enter the Temp \n"; 
    cin >> temp; 

    //Get Soil Moisture 
    string soilMoisture = ""; 
    cout >> "Is the soil Wet or dry? \n"; 
    cin >> soilMoisture; 

     //if red seed 
    if (seedColour == "red") 
    { 
     //if temp >= 75 
     if (temp >= 75) 
     { 

      //if soil is wet 
      if (soilMoisture == "wet") 
      { 
       //Output Sunflower 
       cout << "SUNFLOWER LAR.\n"; 
      } 
      //if soil dry 
      if (soilMoisture == "dry") 
      { 
       //Dandelion 
       cout << "Dandelion.\n"; 
      } 

      //Otherwwise (temp <75) 
      else 
      { 
       //Mushroom 
       cout << "Mushroom"; 

      } 
     } 
    } 

    //if blue 
    if (seedColour == "blue") 
    { 
     //temp between 60 n 70 
     if (temp >= 60 && temp <= 70) 
     { 
      //wet soil 
      if (soilMoisture == "wet") 
      { 
       //Dandilion 
       cout << "Dandilion \n"; 
      } 

      //dry soil 
      if (soilMoisture == "dry") 
      { 
       //Sunflower 
       cout << "Sunflower"; 

      } 
     } 


     //Otherwise 
     else 
     { 
      //mushroom 
      cout << "Mushroom"; 
     } 
    } 
    return 0 
} 

我得到3“有望申报错误。

一个原始{后 “INT主”

其中关于的 “如果”“如果(seedColour == “红”)

一个放在c在“cout < <”蘑菇“之后丢失};”

我也得到一个“‘{’:缺少函数头(旧式正式列表?)”

为什么我得到这些错误? 谢谢!

+0

你为什么包括'',''和''这里?在这种情况下,你实际上只需要''。 ''是用于处理类似C的字符串的函数,即只有'char *'。 ''在1998年C++标准化之前就存在了,现在是纯粹遗留的,不应该使用。 –

回答

1
int main(); 

删除主分号后的分号。

而作为songyuanyao指出:

cout >> "Is the soil Wet or dry? \n"; 

应该

cout << "Is the soil Wet or dry? \n"; 
+2

@JackJones试试'cout << ...' – songyuanyao

+0

谢谢!它没有像预期的那样工作,但无论如何。我们只是说我做到了。再好的一个芽! –

+0

@JJJJones它是'cout <'',一个简单的方法来记住是'cout'你想要它**从**变量到cout,用'cin'你想它从cin **去到TO **变量 –