The following is the complete code. Can you give me a hint as to why the program is reading the "mph" instead of "hours"?? The program should only display the "Distance Traveled" according to how many hours the user inputs, not 40 separate calculations. The user inputs 40 mph and 3 hours. I just need the first 3 hours.
This is the chart I get:
Hours Distance Traveled
----------------------------------
1 40
2 80
3 120
.
.
.
.
.
.
40 1600
This is my code:
int main()
{
system("clear")
double distance, mph, hours;
//Get the data
cout << " What is the speed of the vehicle in MPH? ";
cin >> mph;
cout << " How many hours has it traveled? ";
cin >> hours;
//Display the heading
cout << " Hours\t\tDistance Traveled " << endl;
cout << " ---------------------------------- " << endl;
cout << hours << "\t\t" << distance << endl;
//Input validation
for (hours = 1; hours <= mph; hours++)
{
if (mph < 0 && hours < 0)
{
cout << " Enter a positive number for mph and a value more than 1 for hours. \n";
}
else
cout << " " << hours << "\t\t" << (hours * 40) << endl;
}
return 0;
}