I'm trying to get this program to return total taxi cab fair an infinite number of times, however, when I use the while statement after for and try to run the program, it just keeps displaying the first total fair rapidly. any help would be appreciated as it is due tomorrow lol. thank you guys in advance !
specifications:
A cab company needs a program to calculate the cost of a cab ride.
The driver will enter the length of the trip in miles.
The miles entered must be greater than 0.
Create a function to calculate the charge. The function should receive one argument, the length of the trip, and should return the total fare for the ride.
The taxi charges a fixed charge of $2.50, plus an additional charge of $1.85 per mile.
Allow the user to calculate any number of trips.
At the end display the total of all the fares.
here is my code:
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
|
#include <iostream>
#include <iomanip>
using namespace std;
//function prototypes
double getLength ();
int main ()
{
//declare variables
double lengthTrip = 0.0;
double totalFee = 0.0;
double perMile = 1.85;
//call function to get length in miles and charge
lengthTrip = getLength();
totalFee = 2.50 + (perMile * lengthTrip);
//display total fee
do{
cout << fixed << setprecision(2);
cout << "total fee: $ " << totalFee << endl;
}
while (lengthTrip >= 1);
if (lengthTrip < 1)
cout << "end of program";
return 0;
} //end of main function
//function definitions
double getLength()
{
double lengthTrip = 0.0;
cout << "enter length in miles: ";
cin >> lengthTrip;
return lengthTrip;
} //end of getLength function
|