我的 int main(){} 有问题
Something wrong with my int main(){}
#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"
相关文章:
- 我似乎对if/else的基本语句有问题:/
- 我在范围内未声明的错误类有问题
- 是什么导致了这种使用三进制而不是短整型的有符号int到无符号int转换
- 我的C++语言蛮力算法有问题
- 我关于函数"Assert"的C++代码有问题
- 标准对此指向成员函数类型模板参数有何说明?是我的代码有误,还是 MSVS 16.6 有问题?
- C++类中的友元函数有问题?
- 我对数组即 0x6dfe78 有问题
- 我对 std::unique(算法)C++有问题
- 使用 fstream 库并在屏幕上打印的文件有问题?
- 这个模板为什么有问题?如何正确编译
- 我对 MyGraph 属性顶点名称和边权重有问题
- delete[]有问题,如何部分删除内存
- 在C++中使用exit()退出程序有问题吗
- 跳转到if(false)块有问题吗
- 查找有问题的宏
- 使用 rand() 和 srand() 有问题
- C++ 回文程序总是给出 0(假)作为输出问题;我的代码哪里有问题?
- C++,字符串和int转换有问题
- 我的 int main(){} 有问题