Advertisement
okelikai

pathTime

Sep 24th, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.50 KB | None | 0 0
  1. // using user inputed distance from google heatmap, and converting that into rough estimate of travel time
  2. #include <iostream>
  3. #include <iomanip> // used to set the amount of decimal points printed
  4. #include <cstdlib> // used for random func
  5. using namespace std;
  6.  
  7.  
  8. int main()
  9. {
  10.     double redMiles, yellowMiles, greenMiles;               // distance traveled in each zone
  11.     int redSpeed, yellowSpeed, greenSpeed;                  // randomly generated speed for zones
  12.     double totalRed, totalYellow, totalGreen, totalTime;    // total time in each zone, and total time
  13.  
  14.     srand(time(NULL));               // seeding random variables below
  15.     redSpeed = rand() % 6 + 0;       // red speed from 0-6
  16.     yellowSpeed = rand() % 18 + 12;  // yellow speed from 12-18
  17.     greenSpeed = rand() % 35 + 10;   // green speed form 10-35
  18.  
  19.     cout << fixed << setprecision(2); //this (used from the iomanip library) sets the printed decimal points to hundreths, for aesthetics
  20.     cout << "How many miles of red zone? "; // user input from heat maps online
  21.     cin >> redMiles;
  22.     cout << "How many miles of yellow zone? ";
  23.     cin >> yellowMiles;
  24.     cout << "How many miles of green zone? ";
  25.     cin >> greenMiles;
  26.  
  27.     totalRed = redMiles/redSpeed; //arithimetic, dividing distance by random time
  28.     totalYellow = yellowMiles/yellowSpeed;
  29.     totalGreen = greenMiles/greenSpeed;
  30.     totalTime = (totalRed+totalYellow+totalGreen);
  31.    
  32.     cout << "It will take you " << totalTime << " hours.";
  33.  
  34.     return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement