【发布时间】:2016-04-05 19:30:03
【问题描述】:
每当我尝试运行此游戏时,它都会自动返回 0。 该游戏是我在 Code::Blocks 上编写的基于文本的生存游戏。编译器是 MinGW。我是一个半知识的程序员。编译时没有错误。
// This game automatically returns 0 and ends for some reason...
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <string>
using namespace std;
int hunger;
int warmth;
int thirst;
int choice;
// Declares variables for hunger, warmth, thirst, and the users choice
int start()
{
cout<< "You are stuck in a forest, all alone"<< endl;
cout<< "You must maintain your hunger, thirst, and warmth." << endl;
int mainPage();
}
int hunt()
{
srand(time(0));
cout<< "You have chosen hunt!"<< endl;
if ((rand() % 2) == 2){
cout<< "You caught a deer!"<< endl;
hunger = hunger + 1;
}
else{
cout<< "You could not find anything..."<< endl;
}
int mainPage();
}
// The previous function is used for the hunting choice
int wood()
{
cout<< "You have chosen find firewood!"<< endl;
if ((rand() % 2) == 2){
cout<< "You found firewood!"<<endl;
warmth = warmth + 1;
}
else{
cout<< "You could not find any firewood"<< endl;
}
int mainPage();
}
// Wood choice
int water()
{
cout<< "You have chosen find water!"<< endl;
if ((rand() % 2) == 2){
cout<< "You have found a river!"<< endl;
thirst = thirst + 1;
}
else{
cout<< "You could not find anything..."<< endl;
}
int mainPage();
}
// Water choice
int mainPage()
{
warmth = warmth - 1;
hunger = hunger - 1;
thirst = thirst - 1;
// Subtracts one from each variable per turn
if (hunger == 0){
cout<< "You starved!"<< endl;
cout<< "Game over!"<< endl;
return 0;
}
if (thirst == 0){
cout<< "You became dehydrated!"<< endl;
cout<< "Game over!"<< endl;
return 0;
}
if (warmth == 0){
cout<< "You froze!"<< endl;
cout<< "Game over!"<< endl;
return 0;
}
// You die if any of the variables reach zero
cout<< "Your hunger is"<< hunger<< endl;
cout<< "Your warmth is"<< warmth<< endl;
cout<< "Your thirst is"<< thirst<< endl;
cout<< "What would you like to do?"<< endl;
cout<< "1 = hunt, 2 = find firewood, 3 = find water"<< endl;
cin>> choice;
if (choice = 1){
int hunt();
}
if (choice = 2){
int wood();
}
if (choice = 3){
int water();
}
// The main page that takes the users choice as input and also tells you the amount of each variable
}
int main()
{
hunger = 5;
thirst = 5;
warmth = 5;
int start();
}
// the main function
【问题讨论】:
-
“这个网站说我的问题主要是代码,所以我会复制并粘贴这个” 考虑到您收到此消息是有原因的。使用无意义的填充文本是不合适的!
-
投下我的反对票。请在下次发布问题之前阅读How to ask。
-
对不起,我不应该那样做。
-
因此,下一步是您将问题具体化,以提供一个minimal reproducible example,准确描述您在调试代码时的问题和观察结果。
-
我不知道代码的哪一部分是问题,那是我的问题。如果我在这个评论中有点粗鲁,我很抱歉,但我根本不知道。
标签: c++ compiler-errors