homework help! My code wont execute

Why wont it execute?
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include <iostream>
#include <stdlib.h>
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.