Created
February 2, 2012 22:33
-
-
Save nerdyworm/1726216 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Mike Schmitt | |
//calculates the amount of time it will take to travel a given distance at a given speed. | |
#include <cstdlib> | |
#include <iostream> | |
using namespace std; | |
int main() | |
{ | |
//Input Data | |
string first; | |
string last; | |
float miles = 0; //Distance in Miles | |
float miles_per_hour = 0; //Speed in MPH | |
int hours = 0; //Time in Hours | |
int minutes = 0; //Time in Minutes | |
int seconds = 0; | |
int total_seconds = 0; //Total time in Minutes | |
//Collect Data | |
cout << "Please use the following program to figure out how long it will take you travel any distance at any average speed. Input should be rounded to the nearest whole number." << endl << endl; | |
cout << "Please enter your first and last name: "; | |
cin >> first >> last; | |
cout << "Please enter your average speed in Miles Per Hour: "; | |
cin >> miles_per_hour; | |
cout << "Please enter the distance in miles you are going to travel: "; | |
cin >> miles; | |
//Calculations | |
total_seconds = (miles / miles_per_hour ) * 3600; | |
hours = total_seconds / 3600; | |
minutes = ((total_seconds) - (hours * 3600)) / 60; | |
seconds = ((total_seconds) - ((hours * 3600) + (minutes *60))); | |
//Display Data | |
cout << endl << "Hello " << first << " " << last << ". It will take you " << hours << " hour(s), " << minutes << " minute(s) and " << seconds << " second(s) to travel " << miles << " mile(s) at " << miles_per_hour << " mph." << endl << endl; | |
system("PAUSE"); | |
return EXIT_SUCCESS; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment