Why doesn't this if Statment work?


1
2
3
4
5
6
7
8
if  ( total_weight <= GP_1_tons * tons_in_lbs){
			Train_type = "GP-1";}
else if ( total_weight > GP_1_tons * tons_in_lbs)&&(total_weight <= GP_2_tons * tons_in_lbs){
				Train_type = "GP-2";}
else if (total_weight > GP_2_tons * tons_in_lbs)&&(total_weight <= GP_3_tons * tons_in_lbs){
			Train_type = "GP-3";}
else
Train_type = "Your train weight is too heavy for any of the locomotives";[code]


I'm not sure what I have done wrong, any help wold be much appreciated, Thank You
In your else if's you need to add an outer bracket, like this: (( total_weight > GP_1_tons * tons_in_lbs)&&(total_weight <= GP_2_tons * tons_in_lbs))

The problem with your code is that the && is outside any brackets.
Yup, I just figured it lol Thanks
Topic archived. No new replies allowed.