[/code] I've been taking this C++ course, I like it; however, there are still some things that I can't figure out. I created this game for an assignment. Rock, Paper, Scissors, Lizard, Spock; the game runs perfectly and built to my professors specs except for one thing. The problem is, the game is suppose to be played once and then the program closes (ends) by itself unless there is a tie, then you get to try again until you win/lose. I was using exit() but it would close out the program even it their was a tie. My game menu only has an exit button just so I can work with the code when I was making it, but I must delete it for my finished code. Could really use the help or some insight, please! :)
Enable your function to return an int; I'll leave this to you.
Insert a "return 7" at the end of your function.
Modify your last conditions in your function:
Choice#1:
1 2 3 4 5 6 7
//Remove the last whole branch and insert this:
if(user == computer)
{
cout << "** Game is a tie!! Go again **\n" <<endl;
return 7;//<---6 is your exit key; I'd prefer true/false, but oh well.
}
return 6;//<--- default return for everything else (6 - exit, done with playing)
//{ Edit
if (user == ROCK && computer == ROCK)
{
cout << "** Game is a tie!! Go again **\n" <<endl;
return 7;//<---6 is your exit key; I'd prefer true/false, but oh well.
}
elseif (user == PAPER && computer == PAPER)
{
cout << "** Game is a tie!! Go again **\n" <<endl;
return 7;//<---6 is your exit key; I'd prefer true/false, but oh well.
}
elseif (user == SCISSORS && computer == SCISSORS)
{
cout << "** Game is a tie!! Go again **\n" <<endl;
return 7;//<---6 is your exit key; I'd prefer true/false, but oh well.
}
elseif (user == LIZARD && computer == LIZARD)
{
cout << "** Game is a tie!! Go again **\n" <<endl;
return 7;//<---6 is your exit key; I'd prefer true/false, but oh well.
}
elseif (user == SPOCK && computer == SPOCK)
{
cout << "** Game is a tie!! Go again **\n" <<endl;
return 7;//<---6 is your exit key; I'd prefer true/false, but oh well.
}
}
I'll leave the indentations to you.
The above code was written in the web text editor, no validation was done; it may not possibly work, but it has the general idea.
If you do correctly it should return a integer value, then all you'd need to do is create an escape path.
been fiddling with the code but I get a error when I try to rearrange the code with the above improvisations. I'm still trying to get it though, I don't like giving up.
1>------ Build started: Project: Assignemt2Week6, Configuration: Debug Win32 ------
1> main.cpp
1>main.cpp(59): error C2440: '=' : cannot convert from 'void' to 'int'
1> Expressions of type void cannot be converted to other types
1. main.cpp(72): warning C4244: 'initializing' : conversion from 'time_t' to 'unsigned int', possible loss of data
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========