if statement inside while loop...

I am having trouble with this assignment:

http://preview.tinyurl.com/6jvcsf

I've tried tweaking it to the best of my knowledge and it still keeps printing out the same input value for "deerpop" no matter what I've done. It never executes this line 31 deerpop = (deerpop) - ((deerpop) * (12/100));or line 36, under both if statements. Any advice would be appreciated.

Here was my work:
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
#include <iostream>
#include <stdlib.h>
#include <string>
using namespace std;

int main()

{

int index = 0;
int year;
int deerpop;
int wintertemp;



 cout<<"type in initial year."<<endl;
  cin>>year;
//
 cout<<"type in the animal population for "<<year<<" . "<<endl;
  cin>>deerpop;
 
    
 while (index < 10)
  { 
    year = year + 1;
    cout<<"Enter lowest temperature for "<<year<<"? "<<endl;
    cin>>wintertemp;
    //If the low temperature was 0 degrees or lower, the animal pop. decreases by twelve percent
    if (wintertemp <= 0)
       {
       deerpop = (deerpop) - ((deerpop) * (12/100));
       cout<<"In "<<year<< " the deer population was "<<deerpop<< " ."<<endl;
       }
//if temperature was higher than zero the pop. increases by fifteen ppercent
    if (wintertemp > 0)
       {
       deerpop =  (deerpop) + ((deerpop) * (15/100));
       cout<<"In "<<year<< " the deer population was "<<deerpop<< " ."<<endl;
       }
    
       index = index + 1;  
  }
  

    system ("PAUSE");
    return 0;
}

Last edited on
Yay finally a program I understand :D.
I'll read it and give you a feedback.

Your problem is in bold and underline

1
2
       deerpop = (deerpop) - ((deerpop) *(12/100)); //Replace (12/100) with (0.12)
       deerpop =  (deerpop) + ((deerpop) * (15/100));//Replace (15/100) with (0.15) 


Other than that, it will work just fine!!

Thank you guestgulkan for leaving the answer to me.

Apparently C++ has a problem with x/y. It must be in decimals.
Last edited on
I was going to post the answer but I'll leave it to hannad
Last edited on
Thanks hannad. It finally worked. I'm just laughing at myself right now because you made it so easy with that fix.

Thanks again.
No problem :D
Topic archived. No new replies allowed.