Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // using user inputed distance from google heatmap, and converting that into rough estimate of travel time
- #include <iostream>
- #include <iomanip> // used to set the amount of decimal points printed
- #include <cstdlib> // used for random func
- using namespace std;
- int main()
- {
- double redMiles, yellowMiles, greenMiles; // distance traveled in each zone
- int redSpeed, yellowSpeed, greenSpeed; // randomly generated speed for zones
- double totalRed, totalYellow, totalGreen, totalTime; // total time in each zone, and total time
- srand(time(NULL)); // seeding random variables below
- redSpeed = rand() % 6 + 0; // red speed from 0-6
- yellowSpeed = rand() % 18 + 12; // yellow speed from 12-18
- greenSpeed = rand() % 35 + 10; // green speed form 10-35
- cout << fixed << setprecision(2); //this (used from the iomanip library) sets the printed decimal points to hundreths, for aesthetics
- cout << "How many miles of red zone? "; // user input from heat maps online
- cin >> redMiles;
- cout << "How many miles of yellow zone? ";
- cin >> yellowMiles;
- cout << "How many miles of green zone? ";
- cin >> greenMiles;
- totalRed = redMiles/redSpeed; //arithimetic, dividing distance by random time
- totalYellow = yellowMiles/yellowSpeed;
- totalGreen = greenMiles/greenSpeed;
- totalTime = (totalRed+totalYellow+totalGreen);
- cout << "It will take you " << totalTime << " hours.";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement