PDF 2004054 C Project CAT 2
PDF 2004054 C Project CAT 2
PDF 2004054 C Project CAT 2
CIT, COIMBATORE
“STONE PAPER SCISSOR SPOCK AND
LIZARD GAME”
R.ADHAVAN
2004054
ECE SECTION 2
1. AIM
2. SOFTWARE / PLATFORM USED
3. ALGORITHM
4. FLOWCHART
5. PROGRAM – SOURCE CODE
6. SNIPS OF OUTPUT
7. INFERENCE
8. RESULT
AIM:-
To write a C program to build stone paper scissor spock and lizard game and
project the score of the user .
PLATFORM USED:-
*MinGW C COMPILER
* https://www.programiz.com/c-programming/online-compiler/
START
Start
Does YES
user=co Display “This
round is a Tie”
pm
If user=rock
Display “computer won the
and
game”
comp=paper
If
Display “computer won the
user=paper
game”
and
comp=scisso
r
If
user=snake Display computer won the
and game”
comp=sock
Display “user won the game”
If user=spock
and
comp=paper
If user=rock
and Display “computer won the
comp=spock game”
If Display “computer won the
user=spock game”
and
comp=lizard
If
Display “computer won the
user=lizard
game”
and
comp=spock
If
Display “user won the game”
user=lizard
and
comp=stone
If
user=lizard Display “user won the game”
and
comp=paper
If
user=lizard Display “computer won the
and game”
comp=rock
NO
Display result
Stop
SOURCE CODE: -
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define SIZE 20
#define S 5
struct game
char name[SIZE];
int points;
};
char *rString() {
return str;
char *pString() {
return str;
char *sString() {
return str;
char *kString() {
char *str = malloc(100);
return str;
char *lString() {
strcpy(str, "\n|\n|\n|\n|__\n");
return str;
int main()
struct game g;
FILE *fp,*fp1;
int random;
char c,cp;
int n, opt;
int user=0,comp=0;
char arr[S];
arr [0]='r';
arr[1]='p';
arr[2] = 's';
arr[3] = 'k';
arr[4] = 'l';
char d='y';
fp=fopen("gamefile", "w");
if(fp==NULL){
return 1;
printf("\n\t\t\t\t*****");
printf("\n\t\t\t\t*****");
do{
scanf("%s",g.name);
scanf("%d",&n);
c=arr[n];
random = rand()%5;
cp=arr[random];
if (c==cp){
user++;
comp++;
}
else if (c== 'r' && cp == 'p')
comp++;
user++;
comp++;
user++;
comp++;
user++;
}
else if (c == 'k' && cp == 's')
user++;
comp++;
comp++;
user++;
user++;
comp++;
}
comp++;
user++;
comp++;
user++;
user++;
comp++;
user++;
g.points=user;
fwrite(&g, sizeof(g),1,fp);
user=0, comp=0;
printf("\n-------------------------------------------------------------------------------------------");
scanf("%c",&d);
d=getchar();
}while(d== 'y');
fclose(fp);
scanf("%d",&opt);
if(opt==2)
fp1=fopen("gamefile","r");
if(fp1==NULL)
{
return 1;
printf("\nUsername\tpoints");
printf("\n%s\t\t%d",g.name,g.points);
fclose(fp1);
printf("\n");
--------------------------------------------------------------------------------------------------------------------------------------------------
OUTPUT: -
REFERENCE: -
Stack overflow
Quora
MsMarsovac
RESULT: -
The C program to built a stone paper scissor spock and lizard game and
project the score of the user is performed and verified.