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>
using namespace std;
int main() {
const int N=4;
float startKm[N];
float endKm[N];
float startLevel[N];
float endLevel[N];
int i;
for ( i = 0; i < 4; i++) {
cout << i+1 << " quantums (taxi): " << endl;
cout << "Enter start kilometers : ";
cin >> startKm[i];
cout << "Enter end kilometers: ";
cin >> endKm[i];
cout << "Enter start fuel level: ";
cin >> startLevel[i];
cout << "Enter end fuel level: ";
cin >> endLevel[i];
if(endLevel[i]==startLevel[i]){
cout<<"Data error! End Level==Start Level";
return 0;
}
cout << "=============================="<<endl<<endl;
}
for ( i = 0; i < 4; i++) {
cout << "Kilometers traveled for " << i+1 << " quantums (taxi): " <<
endKm[i]-startKm[i]<<endl;
cout << "Used fuel for " << i + 1 << " quantums (taxi): "<<
startLevel[i]-endLevel[i]<<endl;
cout << "Used fuel per kilometers for " << i+1 << " quantums (taxi): " <<
(endKm[i]-startKm[i]) / (startLevel[i]-endLevel[i])<<endl<<
"========================================"<<endl;
}
return 0;
}
Comments
Leave a comment