Hi y'all!
I'm kinda new to c++ so please excuse my inefficiencies.
Anyways, 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 0 degrees F or colder, the deer population drops by 12%.
If the lowest winter temperature was higher than 0 degrees F, the deer population rises by 15%.

And here is my code:
#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.12);
       cout<<"In "<<year", the deer population is "<<pop2<<endl;
    else if (temp = 0)
       pop2 = pop1 - (pop1 *  0.12);
       cout<<"In "<<year", the deer population is "<<pop2<<endl;
    else
        return 0;
        cout<<"In "<<year", the deer population is "<<pop2<<endl;
    
    if (temp > 0)
       pop2 = pop1 + (pop1 * 0.15);
       cout<<"In "<<year", the deer population is "<<pop2<<endl;
    else 
         return 0;
         cout<<"In "<<year", the deer population is "<<pop2<<endl;
         
    system ("PAUSE");
    return 0;
}

And this is my dilemma:
1. The "system("pause")" doesn't work.
2. I get an error message when I compile.

Somebody PLEASE help me, this thing is driving me crazy!!

Thanks in advance.

~xoxo

>1. The "system("pause")" doesn't work.
>2. I get an error message when I compile.
Well obviously your system call doesn't work if the code won't compile. What's the error message?

[Warning] converting to `int' from `double'

That's not an error, it's a warning telling you that the precision for your floating-point calculations (eg. pop2 = pop1 - (pop1 * 0.12); ) is being truncated.

So now I'll ask what compiler and operating system you use, since you claim that the system call "doesn't work". Oh, and you need to explain exactly what you mean by "doesn't work".

well excuse me, but i'm kinda new to this and haven't mastered the terminologies just yet. in any case, i use 'Dev-C++' and DOS.. and what i mean by it doesn't work is the DOS window closes before i see the output.

well excuse me, but i'm kinda new to this and haven't mastered the terminologies just yet. in any case, i use 'Dev-C++' and DOS.. and what i mean by it doesn't work is the DOS window closes before i see the output.

This program doesn't compile. There will be no output since you can't run it. You have problems before the system ("PAUSE"); .

cout<<"In "<<year", the deer population is "<<pop2<<endl;

You are missing some << operators in this and other lines.

thank you.. that was a lot of help. I'm still getting a few warnings though, and i seem not to be able to find out what the problem is :(

You'll want to clean this section of code up:

if (temp < 0)
       pop2 = pop1 - (pop1 *  0.12);
       cout<<"In "<<year", the deer population is "<<pop2<<endl;
    else if (temp = 0)
       pop2 = pop1 - (pop1 *  0.12);
       cout<<"In "<<year", the deer population is "<<pop2<<endl;
    else
        return 0;
        cout<<"In "<<year", the deer population is "<<pop2<<endl;
    
    if (temp > 0)
       pop2 = pop1 + (pop1 * 0.15);
       cout<<"In "<<year", the deer population is "<<pop2<<endl;
    else 
         return 0;
         cout<<"In "<<year", the deer population is "<<pop2<<endl;

For one, your else if sets temp equal to 0 instead of checking if it's 0. Instead, I suggest you make your first if statement:

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

Get rid of one else, and make the other else statement an error, since there shouldn't be any other answer other than something above 0 or equal to or less than 0, and calling temp2 in that statement wouldn't return anything that made sense anyway.

Also, make sure you have brackets around your code running under an if statement if it's more than one line.

And if with your system pause you're only trying to get it to wait for the user to hit enter before it quits, try replacing it with:

cin.get();
cin.get();
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.