A problem here

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <iostream>
using namespace 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.

Thank you.
Line 32 is wrong. Look closely.
Topic archived. No new replies allowed.