MCPcopy Create free account
hub / github.com/CodeWithHarry/The-Ultimate-C-Programming-Course / main

Function main

Project 2/main.c:5–59  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3#include <time.h>
4
5int main()
6{
7 srand(time(0));
8 int player, computer = rand() % 3;
9 /*
10 0 --> Snake
11 1 --> Water
12 2 --> Gun
13 */
14 printf("Choose 0 for Snake, 1 for water and 2 for Gun \n");
15 scanf("%d", &player);
16 printf("Computer chose %d\n", computer);
17
18 if (player == 0 && computer == 0)
19 {
20 printf("Its a Draw!\n");
21 }
22 else if (player == 0 && computer == 1)
23 {
24 printf("You Win!\n");
25 }
26 else if (player == 0 && computer == 2)
27 {
28 printf("You Lose!\n");
29 }
30 else if (player == 1 && computer == 0)
31 {
32 printf("You Lose!\n");
33 }
34 else if (player == 1 && computer == 1)
35 {
36 printf("Its a Draw!\n");
37 }
38 else if (player == 1 && computer == 2)
39 {
40 printf("You win!\n");
41 }
42 else if (player == 2 && computer == 0)
43 {
44 printf("You win!\n");
45 }
46 else if (player == 2 && computer == 1)
47 {
48 printf("You Lose!\n");
49 }
50 else if (player == 2 && computer == 2)
51 {
52 printf("Its a Draw!\n");
53 }
54 else{
55 printf("Something went wrong!");
56 }
57
58 return 0;
59}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected