Variable that shouldnt increase, increases

I'm trying out a practice program from a textbook where I have to take weight, height and age and then return the waist size by a given formula, but i'm having a problem, i put in 34 as the age so that the if(age>=30) runs, but when it goes into the for loop, the multiple is supposed to be 0, and it is, but it skips if(multiple=0) and turns multiple=1 and runs the else if statement, the code is below

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
void waist(int& weight, int& age){
	int waistSize;
	if (age >= 30){
		int multiple;
		int difference;
		for(int i = 0; i < 30; ++i){
			multiple = i%2;
                        cout << multiple << endl; //multiple = 0 here
			if (multiple = 0){ //but this step gets skipped for some reason
				difference = age-i;
				if (difference = 30){
					waistSize = (double(weight)/waistConst) + ((1/10)*double(i));
					cout << "Waist Size is " << waistSize << endl;
				}
			}
			else if (multiple = 1){ //and runs this step
				cout << multiple << endl; //multiple = 1 here
                                difference = age-i;
				cout << multiple << endl;
				if (difference = 30){
					waistSize = (double(weight)/waistConst) +  ((1/10)*double(i-1));
					cout << "Waist size: " << waistSize << endl;
				}
			}
		}
	}
	else{
		waistSize = double(weight)/waistConst;
	}
}


please help! i appreciate it =D
Hi ar9jun ,

this bit
if (multiple = 0)

should be
if (multiple == 0)

you had assignment when when you needed comparison. same for the others.

HTH
Yeah :D

if (multiple = 0) change to if (multiple == 0)

Classic error, watch out from these, you'll be pounding you're head in the beginning and if you work with multiple languages at the same time.
Last edited on
of course! thank you very much!! it works now =D
Topic archived. No new replies allowed.