// This program will determine the distance a vehicle moving at a spceidifc speed will travel.
#include <iostream>
usingnamespace std;
int main()
{
int Speed, Hours, Distance;
int DisplayNumber, DisplayDistance;
// Ask the user for the speed of a vehicle (in miles per hour).
cout << "Enter the speed at which a vehicle is traveling [in miles per hour] " << endl;
// Do not accept a negative number
cin >> Speed; // Input
while (Speed <= 0)
{
cout << "Error: Enter a positive integer." << endl;
cin >> Speed;
}
// Ask how many hours the vehicle has traveled.
cout << "How many hours has the vehicle traveled? " << endl;
// Do not accept any value less then one.
cin >> Hours; // Input
while (Hours < 1)
{
cout << "Error: Do not enter a value less then one." << endl;
cin >> Hours;
}
// Calculate distance with formula
Distance = Speed * Hours;
cout << "\n";
// The program should then use a loop to display the distance the vehicle has traveled for each hour of that time period.
cout << "Hour Distance Traveled " << endl;
cout << "--------------------------------- " << endl;
for (DisplayNumber = 1; DisplayNumber <= Hours; DisplayNumber++)
cout << DisplayNumber << "\t\t" << (DisplayNumber * Speed) << endl;
cout << "\n";
// Output
cout << "The distance traveled is equal to " << Distance << " miles." << endl;
system("pause");
return 0;
}