Error Fix in C++ Object Oriented Programming | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Error Fix in C++ Object Oriented Programming

I have been making this assignments for a while but can't seem to make use of 2nd option in menu to run the car. can anyone help! Code>>>>>>>>>>>>>>>>> #include <iostream> #include <string.h> using namespace std; class FuelGauge { private: int fuel; bool boolvalue; public: FuelGauge() { fuel=0; boolvalue=1; } FuelGauge(int f) { fuel=f; } void printfuel() { cout<<"The current amount of fuel in gallons is: "<<fuel<<endl; } int fuelin() { if (fuel<15) { fuel=fuel+1; cout<<"Fuel after adding 1 gallon is: "<<fuel<<endl; } else { cout<<"Error! Fuel exceeds the limit of tank capacity!!!"<<endl; } return fuel; } int fuelout() { if (fuel>0) { fuel=fuel-1; } else { cout<<"Error! Fuel tank is empty!!!"<<endl; } return fuel; } int boolreturn() { if (fuel==0) { boolvalue=0; } return boolvalue; } friend class Odometer; }; class FuelGuage; class Odometer{ private: int mileage; int count; public: Odometer() { mileage=0; count=0; } Odometer(int m) { mileage=m; } void printmileage() { cout<<"The current car's mileage is: "<<mileage<<endl; } int addmileage(FuelGauge &s) { if (mileage<999999) { mileage=mileage+1; count=count+1; if (count>24) { count=0; } cout<<"The current fuel of car is: "<<s.fuel<<" and the current mileage of car is: "<<mileage<<endl; } else if (mileage>999999) { mileage=0; } return mileage; } int decfuel(FuelGauge &s) { if (count==24) { s.fuel=s.fuel-1; } return mileage; } }; int main() { int fuel,mileage; cout<<"Enter car's fuel: "<<endl; cin>>fuel; if(fuel>15 || fuel<0) { cout<<"Error! Fuel input is invalid!!!"<<endl; exit; } cout<<"Enter car's mileage: "<<endl; cin>>mileage; if (mileage>999999 ||

4th May 2020, 6:37 AM
Muhammad Abdullah
Muhammad Abdullah - avatar
3 Answers
+ 2
Muhammad Abdullah It is not possible to see error when you share code with question so I will suggest you make this code in Playground and share code here.
4th May 2020, 6:44 AM
A͢J
A͢J - avatar
0
REST OF THE CODE IS HERE! cout<<"Enter car's mileage: "<<endl; cin>>mileage; if (mileage>999999 || mileage<0) { cout<<"Invalid input for mileage!!!"<<endl; } FuelGauge a(fuel); Odometer b(mileage); int ch,ch1,ch2; cout<<"Press 1 to fill the fuel tank by 1 gallon."<<endl; cin>>ch1; do { a.fuelin(); cout<<"Press 5 to stop filling fuel: "<<endl; cin>>ch2; } while (ch2!=5); cout<<"Press 2 to run the car."<<endl; cout<<"Press 3 to know the current amount of fuel."<<endl; cout<<"Press 4 to know the current mileage."<<endl; cin>>ch; int z; z=a.boolreturn(); if (ch==3) { a.printfuel(); } if (ch==2) { while (z==1) { b.addmileage(a)<<b.decfuel(a)<<a.fuelout(); } } if (ch==4) { b.printmileage(); } return 0; }
4th May 2020, 6:39 AM
Muhammad Abdullah
Muhammad Abdullah - avatar
0
Please check the while loop While(z==1){ }
4th May 2020, 7:28 AM
Dasarath Singh