2016-04-29 75 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 **變量 –