Rock paper scissor - try1 fail
#include <stdio.h>
#include<stdlib.h>
#include<time.h>
#include <string.h>
int main() {
// Write C code here
char str1[10];
char str2[10];
printf("Enter your choice between Rock , Paper , Scissor : \n");
scanf("%s",str1);
int a;
srand(time(0));
a = rand()%3+1;
if (a==1){
printf("Rock\n");
strcpy(str2,"Rock");
}
else if (a==2){
printf("Paper\n");
strcpy(str2,"Paper");
}
else if (a==3){
printf("Scissor\n");
strcpy(str2,"Scissor");
}
//rock< paper <scissor<rock
//80 70 90 80
// u c res
// R(80) > P(70) C
// R(80) < S(90) U
// P(70) < R(80) U
// P(70) < S(90) C
// S(90) > R(80) C
// S(90) > P(70) U
if (str1==str2){
printf("Game is Tie\n");
}
else if (str1>str2 && str1=="Rock"){
printf("Computer won\n");
}
else if (str1<str2 && str1=="Rock"){
printf("You Won\n");
}
else if (str1=="Paper" && str2=="Rock"){
printf("You won\n");
}
else if (str1=="Paper" && str2=="Scissor"){
printf("Computer won\n");
}
else if (str1=="Scissor" && str2=="Rock"){
printf("You won\n");
}
else if (str1=="Scissor" && str2=="Paper"){
printf("Computer won\n");
}
return 0;
}
Comments
Post a Comment