-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdas9727_hw3_q4.cpp
46 lines (41 loc) · 1.16 KB
/
das9727_hw3_q4.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
#include <iostream>
using namespace std;
int main() {
const int FLOOR_ROUND = 1;
const int CEILING_ROUND = 2;
const int ROUND = 3;
double realNum;
int userInput;
cout << "Please enter a Real number: " <<endl;
cin >> realNum;
cout << "Choose your rounding method: "<<endl;
cout << "1. Floor round"<<endl;
cout << "2. Ceiling round"<<endl;
cout << "3. Round to the nearest whole number"<<endl;
cin >> userInput;
switch(userInput){
case FLOOR_ROUND:
if(realNum > 0)
cout << (int)realNum <<endl;
else
cout << (int)realNum - 1 <<endl;
break;
case CEILING_ROUND:
if(realNum > 0)
cout << (int)realNum + 1 <<endl;
else
cout << (int)realNum <<endl;
break;
case ROUND:
if(realNum > 0){
cout << (int)(realNum + 0.5) <<endl;
}
else{
cout << (int)(realNum - 0.5) <<endl;
}
break;
default:
cout << "Please re-enter choice of rounding method" << endl;
}
return 0;
}