andynov123
12-04-2011, 04:22 AM
I'm making a rock paper scissors game but I'm having problems having it display if player 1 wins. I know you are probably gonna say that I can't compare an integer with a character but I can't think of any way to rewrite that. If you could fix this line of code how would you?
The line of code I'm talking about is
if (randNum == randNum1){
printf("Tie Game\n\n");}
else if (randNum ==array[0]&& randNum1 == array1[2]){
printf ("Player 1 Wins!");
}
Heres all of it
#include <stdlib.h>
#include<stdio.h>
#include <time.h>
int main(){
char array[3][20] = {"Rock", "Paper", "Scissors"};
char array1[3][20] = {"Rock", "Paper", "Scissors"};
int randNum=0;
int randNum1=0;
char playAgain;
int option=0;
char player1[20]="Andy";
char player2[20]="Spencer";
srand((unsigned)(time(0)));
printf ("Welcome to Rock Paper Scissors\n");
system ("pause");
do{
randNum = rand() % 3;
randNum1 = rand() % 3;
printf("\n%s %s %s Shoot:\n\n", array[0], array[1], array[2]);
printf("\n\t\t%s: %s\n", player1 ,array[randNum]);
printf("\t\t%s: %s\n\n", player2, array1[randNum1]);
if (randNum == randNum1){//line of code to look at.
printf("Tie Game\n\n");}
else if (randNum ==array[0]&& randNum1 == array1[2]){
printf ("Player 1 Wins!");
}
}
}
do {
printf("Do you want to play again?\n1 = Yes\n2 = No(Exit the Program)\n Your Choice: ");
scanf("%c", &playAgain);
fflush(stdin);
if(playAgain == '2') {
printf("Goodbye");
}
else if (playAgain == '1');
else{
system ("cls");
printf("\t\tInvalid Entry\n\t\t");
}
}while (playAgain != '1' && playAgain != '2');
//system ("Pause");
system ("cls");
}while (playAgain != '2');
return 0;}
The line of code I'm talking about is
if (randNum == randNum1){
printf("Tie Game\n\n");}
else if (randNum ==array[0]&& randNum1 == array1[2]){
printf ("Player 1 Wins!");
}
Heres all of it
#include <stdlib.h>
#include<stdio.h>
#include <time.h>
int main(){
char array[3][20] = {"Rock", "Paper", "Scissors"};
char array1[3][20] = {"Rock", "Paper", "Scissors"};
int randNum=0;
int randNum1=0;
char playAgain;
int option=0;
char player1[20]="Andy";
char player2[20]="Spencer";
srand((unsigned)(time(0)));
printf ("Welcome to Rock Paper Scissors\n");
system ("pause");
do{
randNum = rand() % 3;
randNum1 = rand() % 3;
printf("\n%s %s %s Shoot:\n\n", array[0], array[1], array[2]);
printf("\n\t\t%s: %s\n", player1 ,array[randNum]);
printf("\t\t%s: %s\n\n", player2, array1[randNum1]);
if (randNum == randNum1){//line of code to look at.
printf("Tie Game\n\n");}
else if (randNum ==array[0]&& randNum1 == array1[2]){
printf ("Player 1 Wins!");
}
}
}
do {
printf("Do you want to play again?\n1 = Yes\n2 = No(Exit the Program)\n Your Choice: ");
scanf("%c", &playAgain);
fflush(stdin);
if(playAgain == '2') {
printf("Goodbye");
}
else if (playAgain == '1');
else{
system ("cls");
printf("\t\tInvalid Entry\n\t\t");
}
}while (playAgain != '1' && playAgain != '2');
//system ("Pause");
system ("cls");
}while (playAgain != '2');
return 0;}