-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path27_switch_quiz.cpp
More file actions
58 lines (50 loc) · 1.28 KB
/
27_switch_quiz.cpp
File metadata and controls
58 lines (50 loc) · 1.28 KB
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
/*Now I would like you to do a switch statement with breaks
**between the cases. Create a program that asks the user for
**two float numbers. Then asks the user if they would like to:
**add the numbers, subtract the numbers, multiply the numbers,
**divide the numbers.
**The program should then print the numbers with the chosen
**operation and the solution.
*/
#include <iostream>
int main()
{
float in1, in2;
char operation;
float answer;
std::cout<<"Enter two numbers:\n";
std::cin>>in1;
std::cin>>in2;
std::cout<<"Enter the operation '+','-','*','/':\n";
std::cin>>operation;
switch(operation)
{
case('+'): {
answer=in1 + in2;
break;
}
case('-'): {
answer=in1 - in2;
break;
}
case('*'): {
answer=in1 * in2;
break;
}
case('/'): {
answer=in1 / in2;
break;
}
default:
std::cout<<"Illegal operation";
}
std::cout<<in1<<operation<<in2<<" = "<<answer<<"\n";
return 0;
}
/*
Enter two numbers:
3 4
Enter the operation '+','-','*','/':
/
3/4 = 0.75
*/