这个 c++ 代码是怎么回事?
What's up with this c++ code?
我只是在学习使用MVS进行编码,正在观察"https://www.youtube.com/watch?v=f0WuJGhFhlU"
这是代码。。。
#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 main"之后
一个在"if(seedColor="red")的"if"上
一个在收盘}后的"cout<<"蘑菇";"
我还得到了一个"‘{’:缺少函数头(旧式形式列表?)"
为什么我会出现这些错误?谢谢
int main();
删除main后面的分号。
正如宋元耀所指出的:
cout >> "Is the soil Wet or dry? n";
应该是
cout << "Is the soil Wet or dry? n";
相关文章:
- 使用递归的数组的最小值.这是怎么回事
- 我不小心调用了一个没有自己类对象的成员函数.但这是怎么回事呢
- 我使用 OpenMP 的线程越多,执行时间就越长,这是怎么回事?
- 绕道重铸瓷砖层是怎么回事
- 架 (U+67B6) 与en_US不符.UTF-8.这是怎么回事?
- R 中的算术在数字上比整数更快。这是怎么回事?
- 我的代码运行良好,但现在当尝试将其制作成模板时,我遇到了许多看似无关的错误。这是怎么回事?
- 在变量名后声明带有 () 的非内部类型与不使用变量名的行为不同。即 std::map<int,char>x(); - 这是怎么回事?
- 弄清楚这段代码是怎么回事(递归下降案例研究)
- 分配器密集和稀疏是怎么回事?
- 传递引用C++,指针的向量.这是怎么回事?
- __vector_base_common是怎么回事?
- (对象)不命名类型.怎么回事
- 变量已在 .obj 中定义;这是怎么回事?
- Sublime上的EasyClangComplete是怎么回事?
- 重复输出的类型是怎么回事,它如何区分迭代次数和 Ascii 代码?
- 标准::地图使用.这是怎么回事?核心转储?我做得不正确?
- 以下代码是怎么回事?有人可以解释每行吗
- 这个 c++ 代码是怎么回事?
- 令我惊讶的是,这段代码可以正确编译和执行。这是怎么回事?