Help with C++ Homework assignment

Okay here is the assignment:

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'm only at the beginning stages now, I am very, very bad at this class and can not seem to wrap my head around things. I am using Dev C++ 4.9.9.2 on a Windows 7 OS. Here is the code I have so far, I'm just trying to get the input information. from the user but I am still getting errors, even when declaring variables ):

#include <windows.h>
#include <iostream>

using namespace std;
//declaring variables
int main()
int number;
int temp;
int pop;

//initial user data entry
cout << "Please enter the initial year to be examined." <<endl;
cin << number;

cout<< "Please enter the initial deer population for this year."<<endl;
cin<< pop;

cout<< "Please enter the lowest temperature im the winter for the year" (number)<<endl;
cin<< temp;

Can someone help me by pointing out some of my mistakes?

Any help would be greatly appreciated


Bump, please help. I really am trying to pass this course, but we normally code in UNIX in the classroom and doing it at home in Windows is really confusing
You are missing the brackets after int main().

1
2
3
4
int main()
{
	// put your code here
}
OKay, but now I am getting an error in the cin<<number; line

"no match for 'operater<<' in 'std::cin <<number'
Last edited on
it must be
cin >> number;
"cin << number;" You have your operators facing the wrong direction you are telling input to do output, it would be like me trying to throw something forwards and expect it to go backwards.

it should look like this cin >>


Remember cout << always points to cout because it is the output going out

cin >> points to what is being put in.
Last edited on
cout is <<
cin is >>

I'm a beginner in C++ also. Don't know if this is different here, but you may want to try that.
Okay. The program also wants me to ask the user for the lowest winter temp. for 10 consecutive years depending on the year the user enters initially. How do I get the code to do this? must I use a while loop for it?
I'm thinking maybe a FOR loop with a nested if else if statement.

something like this.

1
2
3
4
5
6
7
for(i=1, i<=10, number++)
if(temp < 0){
pop = pop-(pop*.15)
else if(temp >=0 || temp <=25)
pop = pop-(pop*.10)

// and so on 


Again, I'm a beginner also, some of my syntax maybe wrong, so double check it.
wait, what does the i=___ represent?

I have never used a for loop
sherringtonjr, yeah, you're missing ; in ur statements.
Why won't the code work? I went with sherringtonjr's idea :

#include <windows.h>
#include <iostream>

using namespace std;
//declaring variables
int main()
{
int number;
int temp;
int pop;
int i=1;

//initial user data entry
cout << "Please enter the initial year to be examined." <<endl;
cin >> number;

cout<< "Please enter the initial deer population for this year." <<endl;
cin >> pop;

cout<< "Please enter the lowest temperature in the winter for the initial year" <<endl;
cin >> temp;
number++;
// The program will calculate the values for the specified years and print them for the user
if (temp < 0);
{
pop= pop - (pop * .15);
}
else if (temp < 0 || temp <= 25);
{
pop= pop - (pop * .10);
}
else if (temp < 26 || temp <= 30);
{
pop= pop;
{
else if (temp < 31 || temp <= 35);
{
pop= pop + (pop * .12);
{
else (temp < 35);
{
pop= pop + (pop * .14);
}


It's not giving me 14 error messages. I am stumped.
Caprico, thanks.

fiesta, a for loop goes like this for(initialization; expression; increment). So in my above example it should be for(number=1; number<=10; number++)
meaning you start at year 1; go through year 10; in one year increments). Telling it to start at year 1 after each time through the loop add 1 to previous until it gets to 10 and then exit the loop.

I really hope I'm not leading you astray here.

I've led myself astray at this point, I'm just bewildered. Thanks for the explanation, I have replaced the while loop in the above code for the for loop you gave me, which should work better. Do I have to declare the function at some point for the calculations to work? also, how the heck do I make this run so I can see what i'm doing? When we code in UNIX theres a way to run the program even if it is incomplete
I don't even know how to output the numbers given through the else if commands, I also have to round all of them to the nearest whole number.
Seriously about to give up and send my prof. broken code explaining to her that I seriously don't understand this.
Topic archived. No new replies allowed.