我的 int main(){} 有问题

Something wrong with my int main(){}

本文关键字:有问题 int main 我的      更新时间:2023-10-16
#include <iostream>
using namespace std;
char sell;
int crew;
char you [50];
int ships =1;
int money;
int choice;
class ship{
public:
void sell_shii(){
cout<<"Do you wish to seel your ship?"<<endl;
cout<<"1to sell ship and 2to cancel"<<endl;

cin>>sell;
if (sell==1 && ships >0){
cout<<"You sold your ship"<<endl;
ships+=sell;

}else{
cout<<"You didnt sell your ship"<<endl;
}
}
}


int main()
{

cout<<"What is your name captain?"<<endl;
cin>>you;
cout<<"Welcome captain "<<you<<endl;
cout<<"You have "<<ships<<"ship/s";
cout<<"What would you like to do?n 1 buy ships 2 sell shipsn 3 battlen
cin<<choice;
switch (choice)
case 1:
buyship()
break;
case 2:
sellshii()
break;
case 3;
battle();
return 0;
}

我的 int main 所在的"{"似乎不起作用,我做了什么?

出现的错误是

C:UsersEthanDesktopNew folder.IPAC++Ship gamemain.cpp|37|error: new types may not be defined in a return type|
C:UsersEthanDesktopNew folder.IPAC++Ship gamemain.cpp|37|error: extraneous `int' ignored|
C:UsersEthanDesktopNew folder.IPAC++Ship gamemain.cpp|37|error: `main' must return `int'|
C:UsersEthanDesktopNew folder.IPAC++Ship gamemain.cpp|37|error: return type for `main' change to "int"

类定义(声明 main 之前的最后一}(的末尾需要一个分号。

如果没有它,它会认为您正在尝试将类定义为 main 返回类型的一部分,因为两者之间没有分隔符,因此出现错误消息:

error: new types may not be defined in a return type

而且,当然,它也抱怨,因为你没有从main返回int类型(在它扔掉int之后,因为你已经,尽管不知不觉地,指定了一个返回类型(:


error: extraneous 'int' ignored
error: 'main' must return 'int' error: return type for 'main' change to "int"