这个 c++ 代码是怎么回事?

What's up with this c++ code?

本文关键字:怎么回事 代码 c++ 这个      更新时间:2023-10-16

我只是在学习使用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";