我刚学的代码使用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++标准化之前就存在了,现在是纯粹遗留的,不应该使用。 –