Answer to Question #322742 in C++ for Leo

Question #322742

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.


1
Expert's answer
2022-04-03T03:45:04-0400
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS