-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtutorial-3_if_else.c
55 lines (48 loc) · 1.25 KB
/
tutorial-3_if_else.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include<stdio.h>
#include<unistd.h>
int main(){
int n1 = 5; //Number 1
int n2 = 12; //Number 2
int right_answer = n1 * n2; //Calculating the right answer
int your_answer; //Creating your answer value
printf("What is 5 x 12?: "); //Writing console question
fflush(stdout); //still dont know what is this
scanf("%d", &your_answer); //Getting input from keyboard
/* Normal Way
//Checking your answer is equals to right answer
if (your_answer == right_answer){
puts("yup yu made it");
sleep(3);
}
//Checking if you are making an not funny joke
else if (your_answer == 31 || your_answer == 69){
puts("Not funny.");
sleep(3);
}
//Checking is your answer is not correct
else{
puts("uhh sorry dude :(");
sleep(3);
}
*/
// Better way
switch (your_answer)
{
case 60:
puts("yup right answer");
sleep(3);
break;
case 69:
puts("Not funny.");
sleep(3);
break;
case 31:
puts("Not funny");
sleep(3);
break;
default:
puts("pls give me an right answer");
sleep(3);
break;
}
}