Intro to CS with C++ Practice.
I am having trouble figuring out how I can assign the random number that Player 1 and Player 2 get to the string values "p1_string_val" and "p2_string_val". I displayed the code I have so far down below.
Could someone please help me figure out how to assign the random number to the strings? Any further help would also be welcomed! Thank you so much.
INSTRUCTIONS FOR ASSIGN: I have completed step 0 and 1. I need help assigning the random number to the strings and any other help would be helpful.
My code reads as this rn:
"Player one has rock/paper/scissors
Player two has rock/paper/scissors
Please press any key to continue"
- Based off of the numerical values stored inside of P1_int_val and P2_int_val, use if, else, and else if statements to store the following strings in P1_string_val, P2_string_val.
int_val 0 string_val rock
int_val 1 string_val paper
int_val 2 string_val scissors
#include <fstream>
#include <iostream>
#include <string>
#include <time.h>
using namespace std;
void main()
{
int p1_int_val, p2_int_val;
string p1_string_val, p2_string_val;
srand(time(NULL));
p1_int_val = (rand() % 3);
p2_int_val = (rand() % 3);
//to check the random integer are between 0-2
/*cout << "Player one has this " << p1_int_val << endl;
cout << "Player two has this " << p2_int_val << endl; */
if (p1_int_val == 0)
cout << "Player one has rock " << endl;
if (p1_int_val == 1)
cout << "Player one has paper" << endl;
else if (p1_int_val == 2)
cout << "Player one has scissors" << endl;
if (p2_int_val == 0)
cout << "Player two has rock " << endl;
if (p2_int_val == 1)
cout << "Player two has paper" << endl;
else if (p2_int_val == 2)
cout << "Player two has scissors" << endl;
return 0;
}
Once the program has been completed it should display:
//Player one has rock/paper/scissors (depends on what number they got)
//Player two has rock/paper/scissors
//Player one or two has won OR TIE