Help w/ complicated variable test
ok i am pretty new to C here, and have limited programming experience. i know you are thinking "oh god here we go," but don't worry. i don't think it will be that bad.
i want to assign a value to the variable "type" based on tests of variables "build" and "feet". "type" should be either 1,2,3, or 0. I set it to 0 to start and my logic is that if none of the tests are true (i.e. build != b, B, h, or H) it will remain 0. the problem is that i can't get it to work out correctly.
Code:
int type_calc(build, feet){
int type, type1, type2, type3;
type = 0;
/*if any test evaluates to true, the value
returned for that test is 1. then it is just a matter of multiplying each different test by a different number. the tests are mutually exclusive, so you can safely say that each number (1,2,3) corresponds to a different type (copper, coax, twisted
respectively) and 0 is an invalid entry.*/
type = (((build == 'h') || (build == 'H')) && (feet < 20)) +
2*((((build == 'h') || (build == 'H')) && (feet >= 20.0)) ||
(((build == 'b') || (build == 'B')) && (feet < 50.0))) +
3*(((build == 'b') || (build == 'B')) && (feet >= 50.0));
return (type);
}
what am i doing wrong. i have put a million parantheses to attempt to make it work, but to no avail. i think this is true:
1. test 1 never evaluates to true
2. test 2 never evaluates to true for build = 'b' || 'B'
that's what i've seen. i guess there's something wrong with this code, but i can't figure it out for the life of me...
thanks for help in advance.
jungle