I'm having a trouble understanding how to do this assignment.
We are supposed to send a character constant as areference parameter to =
the function GetUserInput six times - to get Odometer Start, Odometer =
End, Hours Start, Hours End, Minutes Start and Minutes End. The =
instructor said that I do not have to initialize (as in (//get total =
mileage) StartReading, but to just send the string. I don't understand =
the syntax for doing this or how to use it in the output statement.
I am also confused about how to do the Average Speed function. Since we =
are required to convert the total time of the trip into minutes, someone =
could travel a hundred miles in two hours, but then it would be 100/120 =
which doesn't make sense. The function for turning minutes into hours =
and minutes also gets an error for using ints. However, we don't want a =
float for this since we have to output the times in hour:minute format.
Any help would be appreciated. The code is below.
TIA,
Linda
//AverageMiles.cpp
//This program computes the average speed
//on a trip.
#include <iostream> //for DevC++
#include <string>
using namespace std;
void GetUserInput (char Prompt[], int &UserInput) {
cout << Prompt << endl;
cin >> UserInput;
return;
}
int HoursInMinutes (int HoursTraveled) {
return HoursTraveled * 60;
}
int AverageSpeed (int TotalMiles, int TravelTimeInMinutes) {
return TotalMiles/TravelTimeInMinutes;
}
void MinutesToHoursAndMinutes (int TravelTimeInMinutes, int &TimeHours,
int &TimeMinutes) {
TravelTimeInMinutes /60 =3D TimeHours;
TravelTimeInMinutes %60 =3D TimeMinutes;
return;
}
int main() {
//get total mileage
char OdometerStart[] =3D "Enter the start odometer reading: ";
int StartReading;
GetUserInput (OdometerStart, StartReading);
char OdometerEnd[] =3D "Enter the end odometer reading: ";
int EndReading;
GetUserInput (OdometerEnd, EndReading);
int TotalMileage =3D EndReading - StartReading;
//get start and end hours; convert hours to minutes
char HourStart[] =3D "Enter hour of start: ";
int StartHour;
GetUserInput (HourStart, StartHour);
char HourEnd[] =3D "Enter hour of stop: ";
int EndHour;
GetUserInput (HourEnd, EndHour);
int TotalHoursInMinutes =3D EndHour - StartHour;
HoursInMinutes (TotalHoursInMinutes);
//get start and end minutes
char MinutesStart[] =3D "Enter minutes of start: ";
int StartMinutes;
GetUserInput (MinutesStart, StartMinutes);
char MinutesEnd [] =3D "Enter minutes of stop: ";
int EndMinutes;
GetUserInput (MinutesEnd, EndMinutes);
int TotalTripMinutes =3D EndMinutes - StartMinutes;
//get average miles
int TotalTravelTime;
TotalTravelTime =3D TotalHoursInMinutes + TotalTripMinutes;
AverageSpeed (TotalMileage, TotalTravelTime);
|