hey, this is my first time posting so please don't be too harsh ...
I am trying to write a program that allows the user to play rock paper scissors against the computer. I am able to create the whole game ... but now i need to put different sections of my code into different functions ... Each color needs to be in it's own separate function ... here's what i have so far ...
#include <iostream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <ctime>
using namespace std;
int main ()
{
int num, compPick;
char resp;
do{
srand (time(0));
compPick = rand () % 3 + 1;
cout << "What do you want to choose?";
cout << "\n\n 1. Rock";
cout << "\n 2. Paper";
cout << "\n 3. Scissors";
cout << "\n 4. Quit";
cout << "\n\n Enter you choice (1 - 4): ";
cin >> num;
switch (num)
{
case 1:
{
if (compPick == 2)
{
cout <<"\nThe computer picked paper, and you picked rock, you lose!\n\n";
}
if (compPick == 3)
{
cout <<"\nThe computer picked scissors, and you picked rock, you win!\n\n";
}
if (compPick == 1)
{
cout <<"\nThe computer picked rock, and you picked rock, it's a draw!\n\n";
}
}
break;
case 2:
{
if (compPick == 1)
{
cout <<"\nThe computer picked rock, and you picked paper, you win!\n";
}
if (compPick == 2)
{
cout <<"\nThe computer picked paper, and you picked paper, it's a draw!\n";
}
if (compPick == 3)
{
cout <<"\nThe computer picked scissors, and you picked paper, you lose!\n";
}
}
break;
case 3:
{
if (compPick == 1)
{
cout <<"\nThe computer picked rock, and you picked scissors, you lose!\n";
}
if (compPick == 2)
{
cout <<"\nThe computer picked paper, and you picked scissors, you win!\n";
}
if (compPick == 3)
{
cout <<"\nThe computer picked scissors, and you picked scissors, it's a draw!\n";
}
}
break;
case 4:
{
cout << endl << endl;
return 2;
}
break;
default:
cout << endl << endl;
cout << num << " is invalid\n\n";
}
cout <<"\n\nDo you want to go again? (y/n) ";
cin >> resp;
cout << endl;
}while ((resp == 'y') || (resp == 'Y'));
return 0;
}
... can anyone help me to put the colored sections into their own separate functions? Thanks!!