-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkalkulator.cpp
64 lines (58 loc) · 1.19 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
/*judul
Program: kalkulator sederhana
author: bagas Rayhan Sebastian
NIM: A11.2022.14715
*/
#include<iostream>
using namespace std;
//kamus
int bil1, bil2;
float hasil;
char ops;
void nginput(){
cout<<" masukkan angka ke-1 : ";
cin>>bil1;
cout<<" masukkan operator : ";
cin>>ops;
cout<<" masukkan angka ke-2 : ";
cin>>bil2;
}
float ngitung(int a, int b, char oper){
// jumlah
if(oper == '+'){
hasil = a + b;
}
else if(oper == '-'){
hasil = a - b;
}
else if((oper == '*')||(oper == 'x')){
hasil = a * b;
}
else if((oper == '/')||(oper == ':')){
hasil = a / b;
}
else{
return 0;
}
return hasil;
}
void tampil(){
if(ops == '+'){
cout<<bil1<<" "<<ops<<" "<<bil2<<" = "<<hasil;
}
else if(ops == '-'){
cout<<bil1<<" "<<ops<<" "<<bil2<<" = "<<hasil;
}
else if((ops == '*')||(ops == 'x')){
cout<<bil1<<" "<<ops<<" "<<bil2<<" = "<<hasil;
}
else if((ops == '/')||(ops == ':')){
cout<<bil1<<" "<<ops<<" "<<bil2<<" = "<<hasil;
}
}
//deskripsi
int main(){
nginput();
ngitung(bil1, bil2, ops);
tampil();
}