#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 ships\n 3 battle\n
cin<<choice;
switch (choice)
case 1:
buyship()
break;
case 2:
sellshii()
break;
case 3;
battle();
return 0;
}
我的“{”其中int main似乎不起作用,我做了什么?
出现的错误是
C:\Users\Ethan\Desktop\New folder.IPA\C++\Ship game\main.cpp|37|error: new types may not be defined in a return type|
C:\Users\Ethan\Desktop\New folder.IPA\C++\Ship game\main.cpp|37|error: extraneous `int' ignored|
C:\Users\Ethan\Desktop\New folder.IPA\C++\Ship game\main.cpp|37|error: `main' must return `int'|
C:\Users\Ethan\Desktop\New folder.IPA\C++\Ship game\main.cpp|37|error: return type for `main' change to "int"
答案 0 :(得分:2)
在您定义}
之前,您需要在课程定义的最后添加分号(最终main
。)
没有它,它认为你试图将类定义为main
的返回类型的一部分,因为两者之间没有分隔符,因此错误消息:
error: new types may not be defined in a return type
当然,它也会抱怨,因为您还没有从int
返回main
类型(因为您已经将int
丢弃了之后)在不知情的情况下,指定了一个返回类型):
error: extraneous 'int' ignored
error: 'main' must return 'int'
error: return type for 'main' change to "int"