Home / utk / cs102 / fa16 / labc / code_snippets / example_lab_session3.cpp
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
/*
 * Example Lab
 *
 * Calculates whether you hit your daily goal or not in feet
 * and outputs them in miles
 * 
 * CS102
 * Clara Nguyen
 */

#include <iostream>
#include <iomanip>

using namespace std;

int main() {
	double feet, miles, goal, goal_miles;
	
	//Get values for goal and feet walked
	do {
		cout << "Goal (In feet): ";
		cin >> goal;
	}
	while (goal < 0);
	
	do {
		cout << "Feet walked: ";
		cin >> feet;
	}
	while (feet < 0);

	//Convert Feet to miles
	miles      = feet / 5280.0;
	goal_miles = goal / 5280.0;

	cout << endl;

	//Print out information in miles
	cout << "Goal  : " << right << fixed << setprecision(2) << setw(5) << goal_miles << endl;
	cout << "Walked: " << right << fixed << setprecision(2) << setw(5) <<      miles << endl;

	//Let the user know whether or not they hit their goals...
	if (feet < goal) {
		cout << "You didn't reach your goal for the day..." << endl;
	} else
	if (feet == goal) {
		cout << "You hit your goal exactly." << endl;
	} else {
		cout << "You have passed your goal!" << endl;
	}

	if (goal == 0)
		cout << "You are really lazy..." << endl;
}