Skip to content

Commit 5a48946

Browse files
committed
Project Completed
1 parent 4c46158 commit 5a48946

File tree

5 files changed

+115
-0
lines changed

5 files changed

+115
-0
lines changed
Binary file not shown.

Projects/Project 1/game.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#include<stdio.h>
2+
#include<stdlib.h>
3+
#include<time.h>
4+
5+
int main(){
6+
int number, guess, nguesses=1;
7+
srand(time(0));
8+
number = rand()%100 + 1; // Generates a random number between 1 and 100
9+
// printf("The number is %d\n", number);
10+
// Keep running the loop until the number is guessed
11+
do{
12+
printf("Guess the number between 1 to 100\n");
13+
scanf("%d", &guess);
14+
if(guess>number){
15+
printf("Lower number please!\n");
16+
}
17+
else if(guess<number){
18+
printf("Higher number please!\n");
19+
}
20+
else{
21+
printf("You guessed it in %d attempts\n", nguesses);
22+
}
23+
nguesses++;
24+
}while(guess!=number);
25+
26+
return 0;
27+
}

Projects/Project 1/random_num_gen.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#include<stdio.h>
2+
#include<stdlib.h>
3+
#include<time.h>
4+
5+
int main(){
6+
int number;
7+
srand(time(0));
8+
number = rand()%100 + 1; // Generates a random number between 1 and 100
9+
printf("The number is %d", number);
10+
return 0;
11+
}

Projects/Project 2/Project 2.pdf

545 KB
Binary file not shown.

Projects/Project 2/game.c

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
#include<stdio.h>
2+
#include<stdlib.h>
3+
#include<time.h>
4+
5+
int snakeWaterGun(char you, char comp){
6+
// returns 1 if you win, -1 if you lose and 0 if draw
7+
// Condition for draw
8+
// Cases covered:
9+
// ss
10+
// gg
11+
// ww
12+
if(you == comp){
13+
return 0;
14+
}
15+
16+
// Non-draw conditions
17+
// Cases covered:
18+
// sg
19+
// gs
20+
// sw
21+
// ws
22+
// gw
23+
// wg
24+
25+
26+
if(you=='s' && comp=='g'){
27+
return -1;
28+
}
29+
else if(you=='g' && comp=='s'){
30+
return 1;
31+
}
32+
33+
if(you=='s' && comp=='w'){
34+
return 1;
35+
}
36+
else if(you=='w' && comp=='s'){
37+
return -1;
38+
}
39+
40+
if(you=='g' && comp=='w'){
41+
return -1;
42+
}
43+
else if(you=='w' && comp=='g'){
44+
return 1;
45+
}
46+
47+
}
48+
int main(){
49+
char you, comp;
50+
srand(time(0));
51+
int number = rand()%100 + 1;
52+
53+
if(number<33){
54+
comp = 's';
55+
}
56+
else if(number>33 && number<66){
57+
comp='w';
58+
}
59+
else{
60+
comp='g';
61+
}
62+
63+
printf("Enter 's' for snake, 'w' for water and 'g' for gun\n");
64+
scanf("%c", &you);
65+
int result = snakeWaterGun(you, comp);
66+
if(result ==0){
67+
printf("Game draw!\n");
68+
}
69+
else if(result==1){
70+
printf("You win!\n");
71+
}
72+
else{
73+
printf("You Lose!\n");
74+
}
75+
printf("You chose %c and computer chose %c. ", you, comp);
76+
return 0;
77+
}

0 commit comments

Comments
 (0)