fork download
  1. //Adhira B cs1a ch5 hw
  2. /*******************************************************************************
  3.  * CALCULATE DISTANCE TRAVELED
  4.  * _____________________________________________________________________________
  5.  * program calculates the distance that was traveled during a set of time
  6.  * using MPH
  7.  *
  8.  * INPUTS
  9.  * Speed - speed of vehicle in MPH
  10.  * Time - hours driven
  11.  *
  12.  * OUTPUTS
  13.  * distance - distance traveled
  14.  ******************************************************************************/
  15. #include <iostream>
  16. using namespace std;
  17. int main()
  18. {
  19. int Speed;
  20. double Time;
  21.  
  22. cout << "What is the vehicles speed in mph? ";
  23. cin >> Speed;
  24.  
  25. // input validation
  26. if (Speed < 0)
  27. cout << "please enter a speed greater than 0 MPH";
  28.  
  29. cout << "\nHow many hours has the vehicle traveled?";
  30. cin >> Time;
  31.  
  32. for (int hour = 0; hour <= Time; ++hour) {
  33. double distance = Speed * hour;
  34. cout << "\nfor " << hour << "hours, you have traveled " << distance << " miles.";
  35.  
  36. }
  37.  
  38. return 0;
  39. }
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
What is the vehicles speed in mph? 
How many hours has the vehicle traveled?
for 0hours, you have traveled 0 miles.