#include <iostream>
usingnamespace std;
string name;
void firstchoice (double firstbranch);
int secondchoice (double secondbranch);
int main()
{
double choice1;
double choice2;
cout << "please put in your name" << endl;
cin >> name;
cout << "Sup, " << name << ", get ready for adventures" << endl;
cout << "\nYOU WAKE UP ALONE AND CONFUSED IN AN ATTIC" << endl;
cout << "You can see a door, and a bloody note on a paper" << endl;
cout << "Do you wish to look at door or note?" << endl;
cout << "1 for door or 2 for note" << endl;
cin >> choice1;
firstchoice (choice1);
cout << "you are now in a beatuful plain, with the door no longer behind you" << endl;
cout << "you can also see a city in the close distance" << endl;
cout << "do you want to examine the city or the vehicle?" << endl;
cout << "1 for vehicle, 2 for city" << endl;
cin >> choice2;
secondchoice (choice2);
if (secondchoice(choice2) == 0)
return 0;
cout << "you are in the city" << endl;
return 0;
}
void firstchoice(double firstbranch)
{
if (firstbranch==1)
{cout << "door is open" << endl;
cout << "you walk out into a beautiful plain." << endl;
cout << "you see a car, and a city near by" << endl;
}
elseif (firstbranch==2)
{
cout << "you read the note" << endl;
cout << "the door is open bozo" << endl;
cout << "you go to the door" << endl;
cout << "to your surprise, the door is open" << endl;
}
}
int secondchoice (double secondchoice)
{
if (secondchoice==1)
{
cout << "you check out the vehicle" << endl;
cout << "It seems to start through a button. /n you press it" << endl;
cout << "the car springs to live, and it takes you to the city of its own accord" << endl;
}
elseif (secondchoice==2)
{
cout << "you look at the city. you decide to start walking towards it" << endl;
cout << "you walk and walk for miles" << endl;
cout << "eventually you collapse" << endl;
cout << "you lose " << endl;
return 0;}
}
Now, the this program is a simple thing illustrating my usage of functions. Using it will currently use two functions, void firstchoice and int secondchoice. Now the problem I am running into is that of getting secondchoice to work. Second choice has 2 possible outcomes, one the player progresses on (which I haven't finished) and second, the player loses. The problem is that no matter which choice is selected, it outputs whats under the two choices twice. I've looked into the problem, and I think it has something to do with the return 0 I've attempted to implement in order to simulate a loss of the game. However, it is a requirement for the program to return a number(in this case im making it zero). Does anyone have a solution that would still make the player lose by returning a value, whilst still solving the problem of doubled outputs?
Though I don't necessarily understand your question, I tried to the best of my abilities to solve it and give you a couple of interesting tools for your game.
Firstly, this line didn't make sense
1 2
if (secondchoice(choice2) == 0)
return 0;
Secondly, in order to slow your code down, you can #include <window.h> in your header so you can use system("PAUSE")
I hope that helps!
If you wanted the if statement to be dependent on choice 2, just make if(secondchoice -== 2)
#include "stdafx.h"
#include <iostream>
#include <string>
#include <Windows.h>
usingnamespace std;
string name;
void firstchoice(double firstbranch);
int secondchoice(double secondbranch);
int main()
{
double choice1;
double choice2;
cout << "please put in your name" << endl;
cin >> name;
cout << "Sup, " << name << ", get ready for adventures" << endl;
cout << "\nYOU WAKE UP ALONE AND CONFUSED IN AN ATTIC" << endl;
cout << "You can see a door, and a bloody note on a paper" << endl;
cout << "Do you wish to look at door or note?" << endl;
cout << "1 for door or 2 for note" << endl;
cin >> choice1;
firstchoice(choice1);
cout << "you are now in a beatuful plain, with the door no longer behind you" << endl;
cout << "you can also see a city in the close distance" << endl;
cout << "do you want to examine the city or the vehicle?" << endl;
cout << "1 for vehicle, 2 for city" << endl;
cin >> choice2;
secondchoice(choice2);
if (choice2 == 1){
cout << "You're in the car going 60 mph hour, aren't you glad you didn't walk?" << endl;
//this is what ever text you want after the player gets in the car
system("PAUSE");
}
cout << "you are in the city" << endl;
return 0;
}
void firstchoice(double firstbranch)
{
if (firstbranch == 1)
{
cout << "door is open" << endl;
cout << "you walk out into a beautiful plain." << endl;
cout << "you see a car, and a city near by" << endl;
system("PAUSE");
}
elseif (firstbranch == 2)
{
cout << "you read the note" << endl;
cout << "the door is open bozo" << endl;
cout << "you go to the door" << endl;
cout << "to your surprise, the door is open" << endl;
system("PAUSE");
}
}
int secondchoice(double secondchoice)
{
if (secondchoice == 1)
{
cout << "you check out the vehicle" << endl;
cout << "It seems to start through a button. /n you press it" << endl;
cout << "the car springs to live, and it takes you to the city of its own accord" << endl;
system("PAUSE");
}
elseif (secondchoice == 2)
{
cout << "you look at the city. you decide to start walking towards it" << endl;
cout << "you walk and walk for miles" << endl;
cout << "eventually you collapse" << endl;
cout << "you lose " << endl;
system("PAUSE");
return 0;
}
}
KillaCosby, about what you said about the line not making sense. The function on option 2 will return a 0. The if statement is so that if that happens, it makes it so that the game will end there, with the selection of #2 for "secondchoice". The problem I was getting was that for whatever choice the player makes for "secondchoice", it displays the cout stuff twice.