HELP! It doesn't work :(

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Dec 2008
Posts: 4
Reputation: capricornia is an unknown quantity at this point 
Solved Threads: 0
capricornia capricornia is offline Offline
Newbie Poster

HELP! It doesn't work :(

 
0
  #1
Dec 9th, 2008
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%.
  1. And here is my code:
  2. #include <iostream>
  3. #include <stdlib.h>
  4. #include <string>
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9. int year;
  10. int pop1;
  11. int pop2;
  12. int temp;
  13. cout<<"Please enter the starting year."<<endl;
  14. cin>>year;
  15. cout<<"Please enter the starting population for the deer."<<endl;
  16. cin>>pop1;
  17. cout<<"What was the lowest winter temperature in "<<year<<endl;
  18. cin>>temp;
  19.  
  20. if (temp < 0)
  21. pop2 = pop1 - (pop1 * 0.12);
  22. cout<<"In "<<year", the deer population is "<<pop2<<endl;
  23. else if (temp = 0)
  24. pop2 = pop1 - (pop1 * 0.12);
  25. cout<<"In "<<year", the deer population is "<<pop2<<endl;
  26. else
  27. return 0;
  28. cout<<"In "<<year", the deer population is "<<pop2<<endl;
  29.  
  30. if (temp > 0)
  31. pop2 = pop1 + (pop1 * 0.15);
  32. cout<<"In "<<year", the deer population is "<<pop2<<endl;
  33. else
  34. return 0;
  35. cout<<"In "<<year", the deer population is "<<pop2<<endl;
  36.  
  37. system ("PAUSE");
  38. return 0;
  39. }
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
Last edited by Narue; Dec 9th, 2008 at 8:16 pm. Reason: added code tags
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,829
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 750
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Senior Bitch

Re: HELP! It doesn't work :(

 
0
  #2
Dec 9th, 2008
>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?
New members chased away this month: 3
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 4
Reputation: capricornia is an unknown quantity at this point 
Solved Threads: 0
capricornia capricornia is offline Offline
Newbie Poster

Re: HELP! It doesn't work :(

 
0
  #3
Dec 9th, 2008
[Warning] converting to `int' from `double'
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,829
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 750
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Senior Bitch

Re: HELP! It doesn't work :(

 
0
  #4
Dec 9th, 2008
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".
New members chased away this month: 3
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 4
Reputation: capricornia is an unknown quantity at this point 
Solved Threads: 0
capricornia capricornia is offline Offline
Newbie Poster

Re: HELP! It doesn't work :(

 
0
  #5
Dec 9th, 2008
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.
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 3,836
Reputation: VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute 
Solved Threads: 503
Featured Poster
VernonDozier VernonDozier is offline Offline
Senior Poster

Re: HELP! It doesn't work :(

 
0
  #6
Dec 9th, 2008
Originally Posted by capricornia View Post
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.
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 4
Reputation: capricornia is an unknown quantity at this point 
Solved Threads: 0
capricornia capricornia is offline Offline
Newbie Poster

Re: HELP! It doesn't work :(

 
0
  #7
Dec 9th, 2008
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
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 4
Reputation: chasee is an unknown quantity at this point 
Solved Threads: 0
chasee chasee is offline Offline
Newbie Poster

Re: HELP! It doesn't work :(

 
0
  #8
Dec 9th, 2008
You'll want to clean this section of code up:
  1. if (temp < 0)
  2. pop2 = pop1 - (pop1 * 0.12);
  3. cout<<"In "<<year", the deer population is "<<pop2<<endl;
  4. else if (temp = 0)
  5. pop2 = pop1 - (pop1 * 0.12);
  6. cout<<"In "<<year", the deer population is "<<pop2<<endl;
  7. else
  8. return 0;
  9. cout<<"In "<<year", the deer population is "<<pop2<<endl;
  10.  
  11. if (temp > 0)
  12. pop2 = pop1 + (pop1 * 0.15);
  13. cout<<"In "<<year", the deer population is "<<pop2<<endl;
  14. else
  15. return 0;
  16. 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:
  1. if (temp <= 0)
  2. {pop2 = pop1 - (pop1 * 0.12);
  3. 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:
  1. cin.get();
  2. cin.get();
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC