Всякий раз, когда я пытаюсь запустить эту игру, она автоматически возвращает 0. Игра представляет собой текстовую игру выживания, которую я закодировал в Code :: Blocks. Компилятор MinGW. Я полу-знающий программист. При компиляции ошибки нет.C++ игра возвращает 0 автоматически
// 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
_ «Этот веб-сайт сказал, что мой вопрос в основном является кодом, поэтому я буду копировать и вставлять это» _ Подумайте, была причина, по которой вы получили это сообщение. Преодоление этого с помощью бессмысленного текста наполнителя не подходит! –
Проиграть и закрыть. Пожалуйста, прочитайте [Как спросить] (http://stackoverflow.com/help/asking) в следующий раз перед отправкой вопроса. –
Прошу прощения, я не должен был этого делать. –