-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMenuarithmeti operations.cpp
141 lines (85 loc) · 2.62 KB
/
CMenuarithmeti operations.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
/*Program Challenge one
Write a program that lets the user perform arithmetic operations on two numbers. Your program must be menu driven, allowing the user to select the operation (+, -, *, or /) and input the numbers. Furthermore, your program must consist of following functions:
1. Function showChoice: This function shows the options to the user and explains how to enter data.
2. Function add: This function accepts two number as arguments and returns sum.
3. Function subtract: This function accepts two number as arguments and returns their difference.
4. Function multiply: This function accepts two number as arguments and returns product.
5. Function divide: This function accepts two number as arguments and returns quotient.*/
#include<stdio.h>
void showChoice();
float add(float, float);
float mul(float, float);
float sub(float, float);
float div(float, float);
int main(){
float total, num1, num2;
int choice;
do{
showChoice();
scanf("%d",&choice);
switch(choice){
case 1:
printf("enter a number:");
scanf("%f",&num1);
printf("enter second number:");
scanf("%f",&num2);
total = add(num1,num2);
printf("the sum of number is %0.2f", total);
break;
case 2:
printf("enter a number:");
scanf("%f",&num1);
printf("enter second number:");
scanf("%f",&num2);
total = sub(num1,num2);
printf("the difference of number is %0.2f", total);
break;
case 3:
printf("enter a number:");
scanf("%f",&num1);
printf("enter second number:");
scanf("%f",&num2);
total = mul(num1,num2);
printf("the product of number is %0.2f", total);
break;
case 4:
printf("enter a number:");
scanf("%f",&num1);
printf("enter second number:");
scanf("%f",&num2);
total = div(num1,num2);
printf("the quotient of number is %0.2f", total);
break;
}
}while(choice!=5);
return 0;
}
void showChoice(){
printf("\n\t\tMenu\n");
printf("\t1:add\n");
printf("\t2;Subtract\n");
printf("\t3:Multiply\n");
printf("\t4:Divide\n");
printf("\t5:Exit\n");
printf("\tplease enter choice");
}
float add(float num1 , float num2){
float total;
total = num1+num2;
return total;
}
float mul(float num1 , float num2){
float total;
total = num1*num2;
return total;
}
float sub(float num1 , float num2 ){
float total;
total = num1-num2;
return total;
}
float div(float num1 , float num2){
float total;
total = num1/num2;
return total;
}