Melokuhle is a very young intelligent and adventurous individual. He has recently bought 4 quantums (taxi) to transport people around the country. As a result, he is planning a trip to Upington. Therefore, he has hired you to write a program in pseudocode as well as in C++ to evaluate the fuel consumption on his 4 cars during the planned trip. The kilometers and fuel level in the tank at the start and end of the journey should be entered by the end-user. Calculate for each car, the fuel used, kilometers traveled, and the overall fuel consumption in kilometers traveled per litre of fuel.
#include <iostream>
#include <iomanip>
using namespace std;
int main() {
float startKilometers[4];
float endKilometers[4];
float startLevel[4];
float endLevel[4];
int i;
for ( i = 0; i < 4; i++) {
cout << i+1 << " taxi: " << endl;
cout << "Enter start kilometers : ";
cin >> startKilometers[i];
cout << "Enter end kilometers: ";
cin >> endKilometers[i];
do{
cout << "Enter start fuel level: ";
cin >> startLevel[i];
cout << "Enter end fuel level: ";
cin >> endLevel[i];
if(endLevel[i]==startLevel[i])
cout<<"The start and end values cannot be equal. Repeat please."<<endl<<endl;
}while(endLevel[i]==startLevel[i]);
cout << endl<<endl;
}
for ( i = 0; i < 4; i++) {
cout << "Kilometers traveled for " << i+1 << " taxi: " << fixed << setprecision(2)<<
endKilometers[i]-startKilometers[i]<<endl;
cout << "Used fuel for " << i + 1 << " taxi: "<<
startLevel[i]-endLevel[i]<<endl;
cout << "Used fuel per kilometers for " << i+1 << " taxi: " <<
(endKilometers[i]-startKilometers[i]) / (startLevel[i]-endLevel[i])<<endl<<
"========================================"<<endl;
}
return 0;
}
Comments
Leave a comment