Directory Listing | |
---|---|
example_lab_session1.cpp
|
|
example_lab_session2.cpp
|
|
example_lab_session3.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
/*
* C++ Feet to Miles Calculator
*
* Takes input in feet (allowing decimals) and converts the value to
* miles and then outputs to the console with a maximum of two decimal
* places.
*
* CS102
* Clara Nguyen
*/
//C++ Includes
#include <iostream>
#include <iomanip>
using namespace std;
int main() {
double miles, feet, goal, goal_miles;
do {
cout << "Input Goal (In Feet): ";
cin >> goal;
}
while (goal < 0);
do {
cout << "Input Feet: ";
cin >> feet;
}
while (feet <= 0);
//Convert Feet to Miles
miles = feet / 5280.0;
goal_miles = goal / 5280.0;
cout << "Goal (In Miles): " << fixed << setprecision(2) << goal_miles << endl;
cout << "Total Miles: " << fixed << setprecision(2) << miles << endl;
//Let the user feel pain
if (goal == 0)
cout << "You are incredibly lazy..." << endl;
//Let the user know if they hit their goal or not.
if (goal > feet) {
cout << "You did not reach your goal!" << endl;
}
else
if (goal == feet) {
cout << "You hit your goal exactly." << endl;
}
else {
cout << "You surpassed your goal. Good Job!" << endl;
}
}