#include <iostream>
#include <string>
#include <cstdlib>
#include <ctime>
using namespace std;
bool win;
int winnings;
int draws;
int loses;
string comChoice;
string playerChoice;
void winGame () {
cout << "You won! Play again?" <<endl;
cout << "Type y/n" <<endl;
char x;
cin >> x;
if (x == 'y') {
beginGame();
} else if ('n'){
cout << "Game Stopped." <<endl;
cout << "Number of Draws: " <<draws << endl;
cout << "Number of Loses: " <<loses << endl;
cout << "Number of Wins: " << winnings << endl;
win = true;
}
}
void drawGame (){
++draws;
cout << "Draw! Try again" << endl;
return;
}
void lose () {
cout << "You lose! Try again?" <<endl;
cout << "Type y/n" <<endl;
char feedback;
cin >> feedback;
if (feedback == 'y') {
beginGame();
} else if ('n'){
cout << "Game Stopped." <<endl;
cout << "Number of Draws: " <<draws << endl;
cout << "Number of Loses: " <<loses << endl;
cout << "Number of Wins: " << winnings << endl;
}
}
void beginGame() {
cout << "Welcome to the Rock, Paper and Scissors Game!" <<endl;
cout << "Let's begin. Type <rock, paper, scissors> for your choice!" <<endl;
cin >> playerChoice;
srand(time(0));
int randomizer = 1+(rand()%3);
if (randomizer == 1)
comChoice = "rock";
if (randomizer == 2)
comChoice = "paper";
if (randomizer == 3)
comChoice = "scissors";
do {
if (playerChoice == comChoice) {
drawGame();
}
if (playerChoice == "rock" && comChoice == "paper")
++loses;
lose();
if (playerChoice == "rock" && comChoice == "scissors")
++winnings;
winGame();
if (playerChoice == "paper" && comChoice == "rock")
++winnings;
winGame();
if (playerChoice == "paper" && comChoice == "scissors")
++loses;
lose();
if (playerChoice == "scissors" && comChoice == "rock")
++loses;
lose();
if (playerChoice == "scissors" && comChoice == "paper")
++winnings;
winGame();
}while (win != true);
}
int main () {
beginGame();
return 0;
}
|
|
|||||||||||||
|
closed as off topic by Jonathan Hobbs, Byte56, Noctrine♦ Jun 24 '12 at 17:15
Questions on Game Development Stack Exchange are expected to relate to game development within the scope defined in the FAQ. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about closed questions here.
|
Your Furthermore you don't use braces in your multi-lines conditional statements, so I had to fix that too. And finally I modified the
There is still more stuff to fix, but I hope that helps. You should give more consideration to your questions however. |
||||
|
|
|
You need to work on how you ask questions, because as it is now, you're not even asking anything. You probably want to know why the program doesn't compile, and I will tell you this: how would a function know about another function if you didn't tell the program that it exists yet (in C++)? |
||||