#include <iostream>
usingnamespace std;
class Car {
public:
Car(double a,double b) {oil_weight = a; car_weight = b;check();}
void check();
private:
double oil_weight;
double car_weight;
};
void Car::check()
{
if (oil_weight>car_weight)
cout<<"Rule 1 violated"<<endl;
if (oil_weight>100.0)
cout<<"Rule 2 violated"<<endl;
if (car_weight>1000.0)
cout<<"Rule 3 violated"<<endl;
}
int main()
{
cout<<"Restriction:"<<endl
<<"(1) Oil weight cannot be heavier than car weight"<<endl
<<"(2) Oil weight cannot be heavier than 100kg"<<endl
<<"(3) Car weight cannot be heavier than 1000kg"<<endl;
cout<<"Now enter the oil weight and car weight:";
double oilw,carw;
cin>>oilw,carw;
Car(oilw,carw);
system("pause");
}
I just want to ask why in Line 6, the function check() cannot work probably.No matter what numbers I insert, it always gives me the "Rule 1 violated" message.