1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
|
#include <iostream>
#include <iomanip>
using namespace std;
//Funtions
void velocidad (float &speed1);
void tiempo (float &time1);
void calc (float &distance1, float time1, float speed);
void impresion (float i1, float time1, float &distance1);
// Sentinel
int sentinel;
int main()
{
do{
float distance, speed, time,i;
i= time;
cout<<"This program will calculate distance traveled.\n";
cout<<"ONLY positive number will be accepted for calculations\n\n";
velocidad (speed); //gets me the speed
tiempo (time); //gets me the time
calc (distance,time,speed); //calculates
impresion (i, time, distance); //prints
cout <<"Your calculated distance is: "<<distance<<endl;
cout << "Press 0 to exit or any number to continue: ";
cin>> sentinel;
}while (sentinel != 0);
return 0;
}
void velocidad (float &speed1)
{
do{
cout<<"Please enter the speed (miles): ";
cin >> speed1;
}
while (speed1 <0);
}
void tiempo (float &time1)
{
do{
cout << "\nPlease enter the time (hours): ";
cin >> time1;
}
while(time1 <1);
}
void calc (float &distance1, float time1, float speed1)
{
distance1 = speed1 * time1;
}
void impresion (float i1, float time1, float &distance1)
{
cout << "Hour" << setw(20) << " Distance Traveled" << setw(10) << endl;
for (i1 = 0; i1 < time1; i1++) {
cout << time1 << setw(15) << distance1 << setw(10) << endl;}
}
| |