我剛學的代碼使用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 < <」蘑菇「之後丟失};」
我也得到一個「‘{’:缺少函數頭(舊式正式列表?)」
爲什麼我得到這些錯誤? 謝謝!
你爲什麼包括'',''和''這裏?在這種情況下,你實際上只需要''。 ''是用於處理類似C的字符串的函數,即只有'char *'。 ''在1998年C++標準化之前就存在了,現在是純粹遺留的,不應該使用。 –