You are using a version without Ads of this website. Please, consider donating:

### homework help! My code wont execute

Why wont it execute?
 ``12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970`` ``````#include #include using namespace std; int main () { int index =0; int temp; int population; int year; int newpop; cout << "Please enter the starting year" << endl; // This is to ask for the starting year cin >> year; cout << "Please enter the starting population for the deer." << endl; // This is to ask for the starting population cin >> population; while (index <10) { cout << "What was the lowest temperature in " << year << "?" << endl; // This asks forthe lowest temperature cin >> temp; { if (temp <= 0) { newpop = (population) - (population * (.15)); cout <<"In spring " << year << " the deer population was " << newpop << endl; } else if (0 <= temp) && (temp <= 25) { newpop = (population) - (population * (.1)); cout <<"In spring " << year << " the deer population was " << newpop << endl; } else if (26 <= temp)&& (temp <= 30) { newpop = population; cout <<"In spring " << year << " the deer population was " << newpop << endl; } else if (31 <= temp) && (temp <= 35) { newpop = (population) + (population * (.12)); cout <<"In spring " << year << " the deer population was " << newpop << endl; } else; { newpop = (population) + (population * (.14)); cout <<"In spring " << year << " the deer population was " << newpop << endl; } population = newpop; year++; index++; } } system ("PAUSE"); return 0; } ``````
Last edited on
It doesn't compile because of missing parentheses around the condition of the if statements.
`if ((0 <= temp) && (temp <= 25))`
`if (0 <= temp && temp <= 25)`

I think operator precedence will prioritize the comparison statements, then the logical statements.
@Bourgond Aries

The original code unfortunately deleted was like this:
`if (0 <= temp) && (temp <= 25)`
Topic archived. No new replies allowed.