-
Notifications
You must be signed in to change notification settings - Fork 239
/
aritmatika.c
162 lines (132 loc) · 4.08 KB
/
aritmatika.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#include <stdio.h>
void main () {
// Make variabel for string and integer
char opera, repeat;
int a, b;
// Greeting words XD
printf("Welcome to smart calculator, enjoy!\n\n");
// Get input a first number from user
printf("Enter your first number: ");
scanf(" %d", &a);
// Get input a second number from user
printf("Enter your second number: ");
scanf(" %d", &b);
// Get input a operator from user
printf("\n\nEnter your operator to use\n");
printf("+, -, *, / : ");
scanf(" %c", &opera);
// Show the operator output you input earlier
printf("You entered this operator: %c\n ", opera);
// Create a simple conditional algorithm with switch
switch (opera) {
case '+':
printf("\nResult: %d", a + b);
break;
case '-':
printf("Result: %d", a - b);
break;
case '*':
printf("\nResult: %d", a * b);
break;
case '/':
printf("\nResult: %d", a / b);
break;
default:
printf("\n\nYou enter a wrong operator, try again!\n");
cuk();
break;
}
/* Asking to the user do you guys want to repeat this program or no?
if you type 'y' the program will be looping, if you type 'n' the program will be end.*/
printf("\n\nDo you want to repeat this program?\n");
printf("Answer(y/n): ");
scanf(" %c", &repeat);
// Create a simple conditional with if elseif and else
if(repeat == 'y') {
cuk();
} else if(repeat == 'n') {
printf("\n\nThanks for using this program, have a good one!\n\n");
printf("Made with a cup of coffe and tea, by rama.\n");
} else {
printf("\n\nI say, do you want to repeat this program?\n");
printf("Answer(y/n): ");
scanf(" %c", &repeat);
/* I f*cked up the code, i'm sorry. But it's working. You can try it!.
I just add some conditional again so as the code running normaly.
It's can be cool if you guys make a clean conditional.*/
if(repeat == 'y') {
cuk();
} else if(repeat == 'n'){
printf("\n\nThanks for using this program, have a good one!\n\n");
} while(repeat != 'y' && 'n') {
printf("\n\nI say, do you want to repeat this program?\n");
printf("Answer(y/n): ");
scanf(" %c", &repeat);
if(repeat == 'y') {
cuk();
} if(repeat == 'n'){
printf("\n\nThanks for using this program, have a good one!\n\n");
break;
}
}
}
}
/* Another function without greeting welcome, like a earlier function. It's make them different.
Look the code in the bottom. I just re write this code from the first code or function when i make earlier.*/
void cuk () {
char opera, repeat;
int a, b;
printf("\nEnter your first number: ");
scanf(" %d", &a);
printf("Enter your second number: ");
scanf(" %d", &b);
printf("\n\nEnter your operator to use\n");
printf("+, -, *, / : ");
scanf(" %c", &opera);
printf("You entered this operator: %c\n ", opera);
switch (opera) {
case '+':
printf("\nResult: %d", a + b);
break;
case '-':
printf("Result: %d", a - b);
break;
case '*':
printf("\nResult: %d", a * b);
break;
case '/':
printf("\nResult: %d", a / b);
break;
default:
printf("\n\nYou enter a wrong operator, try again!\n");
cuk();
break;
}
printf("\n\nDo you want to repeat this program?\n");
printf("Answer(y/n): ");
scanf(" %c", &repeat);
if(repeat == 'y') {
cuk();
} else if(repeat == 'n') {
printf("\n\nThanks for using this program, have a good one!\n\n");
} else {
printf("\n\nI say, do you want to repeat this program?\n");
printf("Answer(y/n): ");
scanf(" %c", &repeat);
if(repeat == 'y') {
cuk();
} else if(repeat == 'n') {
printf("\n\nThanks for using this program, have a good one!\n\n");
} while (repeat != 'y' && 'n') {
printf("\n\nI say, do you want to repeat this program?\n");
printf("Answer(y/n): ");
scanf(" %c", &repeat);
if(repeat == 'y') {
cuk();
} if(repeat == 'n'){
printf("\n\nThanks for using this program, have a good one!\n\n");
break;
}
}
}
}