Anh chị cho em hỏi tí ạ, đoạn code em gõ thầy giáo bảo là đúng nhưng logic có vấn đề. Mọi người giúp em được không ạ. Em cảm ơn
#include<iostream.h>
class Car
{
public:
void init(double,double);
double getEff() {return gas; }
double checkGas() {return gas; }
double go(double);
private:
double gas;
double eff;
};
double Car::go( double kilo)
{
if (gas >= (kilo/eff))
{
gas -= kilo/eff;
cout << " Tank only left " << checkGas() << " Liter gas " << endl;
if (gas==0)
cout << " no gas ! ";
}
else
{
cout << " gas not enough, Tank's gas only cas run "
<< (kilo = gas * eff)<<" Km ";
gas = 0 ;
}
return kilo;
}
void Car::init(double G, double E)
{
gas = G;
eff = E;
}
int main(void)
{
Car super;
super.init(20,30);
cout << " 1 liter gas can run "<< super.getEff()
<< " Km " << endl;
cout << " Tank have " << super.checkGas() << " liter gas, now " << endl;
while ( super.checkGas() > 0 )
{
double kilo;
cout << " How many Km do you run : ";
cin >> kilo ;
super.go(kilo);
}
return 0;
}