C++ program to estimate the springtime count of deer in a park for 10 consecutive years

Hey guys I need help with this problem:
Write a C++ program to estimate the springtime count of deer in a park for 10 consecutive years.
The population of any given year depends on the previous year's population according to the following calculation:
• If the lowest winter temperature was less than 0 degrees, the deer population drops by 15%.
• If the lowest winter temperature was between 0 degrees F and 25 degrees F (inclusive), the deer population drops by 10%.
• If the lowest winter temperature was between 26 degrees F and 30 degrees F (inclusive), the deer population doesn’t change.
• If the lowest winter temperature was between 31 degrees F and 35 degrees F (inclusive), the deer population rises by 12%.
• If the lowest winter temperature was higher than 35 degrees F, the deer population rises by 14%.

I have started with:

#include <iostream>
#include <stdlib.h>
#include <string>
using namespace std;
int main()
{
int year;
int pop1;
int pop2;
int temp;
cout<<"Please enter the starting year."<<endl;
cin>>year;
cout<<"Please enter the starting population for the deer."<<endl;
cin>>pop1;
cout<<"What was the lowest winter temperature in "<<year<<endl;
cin>>temp;
if (temp <= 0)
{pop2 = pop1 - (pop1 * 0.15);
cout << "In "<< year << ", the deer population is " << pop2 << endl;}
else if (temp <= 25);
{pop2 = pop1 - (pop1 * 0.10);
cout<< "In " <<year << ", the deer population is " <<pop2 << endl; }

}

HELP!
You will want to use the AND operator for situations like this.

For example, for the case where the temperature is between 0 and 25, a sample code looks like this :

 
if(temp>0 && temp<=25)
I have added that I still am getting errors
I will give you a hint. The problem is with your syntax in the "else if" at the end of the program. It would help if the code was formatted properly:
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
int main()
{
    //variables
    int year;
    int pop1;
    int pop2;
    int temp;

    //prompt for input
    cout<<"Please enter the starting year."<<endl;
    cin>>year;
    cout<<"Please enter the starting population for the deer."<<endl;
    cin>>pop1;
    cout<<"What was the lowest winter temperature in "<<year<<endl;
    cin>>temp;

    if (temp <= 0)
    {
        pop2 = pop1 - (pop1 * 0.15);
        cout << "In "<< year << ", the deer population is " << pop2 << endl;
    }
    else if (temp <= 25);
    {
        pop2 = pop1 - (pop1 * 0.10);
        cout<< "In " <<year << ", the deer population is " <<pop2 << endl; 
    }
}


Can you spot the problem?
Topic archived. No new replies allowed.