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?
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
"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
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?
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.
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'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.