Hello everyone, I am having trouble fine tuning my code. I like to have all the bulky parts of my main in functions, and I can not seem to figure out how to write this code as a function. Anyone tell me where to start?
int main()
{
int player = 0;
int computer = 0;
int tie = 0;
do {
char userChoice;
char compChoice;
compChoice = getCompChoice();
userChoice = getUserChoice();
cout << "User picked: " << userChoice << endl;
cout << "Computer picked: " << compChoice << endl;
if (compChoice == userChoice) {
cout << "It's a tie.\n";
tie += 1;
} else if ((compChoice == 'R') && (userChoice == 'S')) {
cout << "Rock smashes scissors. You Lose.\n";
computer += 1;
} else if ((compChoice == 'P') && (userChoice == 'R')) {
cout << "Paper covors rock. You Lose.\n";
computer += 1;
} else if ((compChoice == 'S') && (userChoice == 'P')) {
cout << "Scissors cut paper. You Lose.\n";
computer += 1;
} else if ((compChoice == 'R') && (userChoice == 'P')) {
cout << "Paper covors rock. You Win.\n";
player += 1;
} else if ((compChoice == 'P') && (userChoice == 'S')) {
cout << "Scissors cut paper. You Win.\n";
player += 1;
} else if ((compChoice == 'S') && (userChoice == 'R')) {
cout << "Rock smashes scissors. You Win.\n";
player += 1;
}
cout << "User: " << player << endl
<< "Computer: " << computer << endl
<< "Ties: " << tie << endl;
} while (doItAgain());
return (0);
}
Thats my main this is the code I would like to be a function.
if (compChoice == userChoice) {
cout << "It's a tie.\n";
tie += 1;
} else if ((compChoice == 'R') && (userChoice == 'S')) {
cout << "Rock smashes scissors. You Lose.\n";
computer += 1;
} else if ((compChoice == 'P') && (userChoice == 'R')) {
cout << "Paper covors rock. You Lose.\n";
computer += 1;
} else if ((compChoice == 'S') && (userChoice == 'P')) {
cout << "Scissors cut paper. You Lose.\n";
computer += 1;
} else if ((compChoice == 'R') && (userChoice == 'P')) {
cout << "Paper covors rock. You Win.\n";
player += 1;
} else if ((compChoice == 'P') && (userChoice == 'S')) {
cout << "Scissors cut paper. You Win.\n";
player += 1;
} else if ((compChoice == 'S') && (userChoice == 'R')) {
cout << "Rock smashes scissors. You Win.\n";
player += 1;
}