-
Notifications
You must be signed in to change notification settings - Fork 0
/
Kalkulator.cpp
144 lines (130 loc) · 3.2 KB
/
Kalkulator.cpp
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
#include <iostream>
#include <math.h>
#include <conio.h>
using namespace std;
//Compiler version g++ 6.3.0
//void
void penjumlahan (float num1, float num2)
{
float hasil;
hasil = num1+num2;
cout<<num1<<" + "<<num2<<" = "<<hasil;
}
void pengurangan (float num1, float num2)
{
float hasil;
hasil = num1-num2;
cout<<num1<<" - "<<num2<<" = "<<hasil;
}
void pembagian (float num1, float num2)
{
float hasil;
hasil = num1/num2;
cout<<num1<<" : "<<num2<<" = "<<hasil;
}
void perkalian (float num1, float num2)
{
float hasil;
hasil = num1*num2;
cout<<num1<<" x "<<num2<<" = "<<hasil;
}
void modulusuy (int num1, int num2)
{
int hasil;
hasil = num1%num2;
cout<<num1<<" % "<<num2<<" = "<<hasil;
}
//DIMANA PROGRAM DIMULAI
int main()
{
//Deklarasi
float num1, num2, hasil;
int oprt;
char x, H;
string t = "Masukkan ";
string m1 = "Masukkan num1: ";
string m2 = "Masukkan num2: ";
//TABEL OPERATOR
kembalioprt:
cout<<".____________________.\n";
cout<<"|___TABEL OPERATOR___|\n";
cout<<"| 1. Penjumlahan |\n";
cout<<"| 2. Pengurangan |\n";
cout<<"| 3. Pembagian |\n";
cout<<"| 4. Perkalian |\n";
cout<<"| 5. Modulus |\n";
cout<<"|____________________|\n";
//MEMASUKKAN OPERATOR
cout<<t<<"operator = ";
cin>>oprt;
switch (oprt)
{
case 1:cout<<"\n\n";
break;
case 2:cout<<"\n\n";
break;
case 3:cout<<"\n\n";
break;
case 4:cout<<"\n\n";
break;
case 5:cout<<"\n\n";
break;
default:system("cls");
cout<<"input yang kamu masukkan salah!!\n\n";
goto kembalioprt;
}
pertanyaan_oprt:
//MENGGANTI OPERATOR?Y/N
cout<<"Ingin mengganti operator?(y/n)";
cin>>x;
switch (x)
{
case 'y': system("cls");
cout<<"\nKembali ke pemilihan operator\n\n";
goto kembalioprt;
break;
case 'n': cout<<"\n";
break;
default: cout<<"\ninput yang anda masukkan salah!!\n\n";
system("cls");
goto pertanyaan_oprt;
break;
}
//MEMASUKKAN ANGKA NUM1 DAN NUM2
cout<<m1;
cin>>num1;
cout<<m2;
cin>>num2;
switch (oprt)
{
case 1:penjumlahan(num1,num2);
break;
case 2:pengurangan(num1,num2);
break;
case 3:pembagian(num1,num2);
break;
case 4:perkalian(num1,num2);
break;
case 5:modulusuy(num1,num2);
break;
}
//PERTANYAAN UNTUK SELESAI
pertanyaan:
cout<<"\n\nApakah Anda ingin menggunakan lagi?(y/n)";
cin>>H;
if (H == 'y')
{
system("cls");
cout<<"\nKembali ke pilih operator :D\n\n";
goto kembalioprt;
}
else if (H == 'n')
{
cout<<"Okaay, Byee see you next time :)\n\n";
}elses
{
cout<<"inputmu salah, Kembali ke pertanyaan!\n\n";
goto pertanyaan;
}
return 1;
}