Answer to Question #322738 in C++ for Leo

Question #322738

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-03T07:59:52-0400
#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;
}

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