Home / utk / cs102 / fa16 / labc / code_snippets / example_lab_session1.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
/*
 * Example Lab
 * 
 * Calculates if we hit goal footsteps in a day
 * Clara Nguyen
 */

#include <iostream>
#include <iomanip>

using namespace std;

int main() {
	double goal, goal_miles, feet, miles;

	//Get the information about our goal and feet walked
	do {
		cout << "Enter Goal (In Feet): ";
		cin >> goal;
	}
	while (goal < 0);
	
	do {
		cout << "Enter Feet walked: ";
		cin >> feet;
	}
	while (feet < 0);

	//Calculate miles for our goal and feet walked
	miles      = feet / 5280.0;
	goal_miles = goal / 5280.0;
	
	cout << "You walked    " << setw(5) << fixed << setprecision(2) << right << miles << " miles." << endl;
	cout << "Your goal was " << setw(5) << fixed << setprecision(2) << right << miles << " miles." << endl;

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

	if (feet > goal) {
		cout << "You have made your goal for the day!" << endl;
	}
	else
	if (feet < goal) {
		cout << "You have not made your goal..." << endl;
	}
	else {
		cout << "You hit your goal exactly for the day" << endl;
	}
}