Hi.. so i have 4 problems in my program.
#1.Whatever i chose, the computer will always play (1st)Paper,(2nd)Paper and (3rd)Scissor.
For example:
(1st play)
Enter your choice:1/2/3
You chose rock/paper/scissors
Computer got paper
Computer won
(2nd play)
Enter your choice:1/2/3
You chose rock/paper/scissors
Computer got paper
Computer won
(3rd play)
Enter your choice:1/2/3
You chose rock/paper/scissors
Computer got scissors
You won
Is my code correct?? comp=1+rand()%3;
#2.I want to print out the current score every time i chose.
For example:
1st play i win/lose/tie then the score will display then 2nd the score will change.. and so on..(CAN IT BE??)
#3.When i enter an invalid number the computer will play itself.
For example:
Invalid Input
Computer got rock
How can i stop the response of the computer.
#4.It is the same with #3 when i input a non-numbers the game will immediately end.
1) You should seed your random generator with non-predictable value so it won't give you the same result each time
for std::rand() you may use std::strand(std::time(0)) (and include <cstdlib> and <ctime>)
2) Move bracked from line 94 to line 98
3) Make a loop on player input and do not let leave until number is correct
4) As above, but check for stream status/clean stream. Learn how to do it yourself.
how about this code... it is only working in numbers.. when i enter for example a letters, the programs will infinite looping...
How can i also invalid the letters or any other keys in the keyboard (except 1,2 and 3)
1 2 3 4 5 6 7 8 9
printf("\t\t\t Enter your choice: ");
scanf("%d",&userinput);
while(userinput<1||userinput>3)
{
printf("%d is not a valid number!\n",userinput);
printf("Please select 1 for rock, 2 for paper, and 3 for scissors:");
scanf("%d",&userinput);
}