| | |
HELP! It doesn't work :(
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Dec 2008
Posts: 4
Reputation:
Solved Threads: 0
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 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
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%.
C++ Syntax (Toggle Plain Text)
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; }
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
That's not an error, it's a warning telling you that the precision for your floating-point calculations (eg.
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".
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
•
•
Join Date: Jan 2008
Posts: 3,836
Reputation:
Solved Threads: 503
•
•
•
•
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.
system ("PAUSE"); .cout<<"In "<<year", the deer population is "<<pop2<<endl;You are missing some
<< operators in this and other lines. •
•
Join Date: Sep 2008
Posts: 4
Reputation:
Solved Threads: 0
You'll want to clean this section of code up:
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:
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:
C++ Syntax (Toggle Plain Text)
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;
C++ Syntax (Toggle Plain Text)
if (temp <= 0) {pop2 = pop1 - (pop1 * 0.12); cout << "In "<< year << ", the deer population is " << pop2 << endl;}
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:
C++ Syntax (Toggle Plain Text)
cin.get(); cin.get();
![]() |
Similar Threads
- Need 2 techies for tech-support, work from home (Tech / IT Consultant Job Offers)
- Requesting shadowing work at home job (Software Development Job Offers)
- 3D Engine Developer Needed from India - Work from home (Web Development Job Offers)
Other Threads in the C++ Forum
- Previous Thread: passing fstream to a function and searching for a string
- Next Thread: SDL Playing Music
| Thread Tools | Search this Thread |
Tag cloud for C++
api application array arrays based beginner binary bmp c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete deploy developer display dll dynamiccharacterarray email encryption error file format forms fstream function functions game generator givemetehcodez graph homeworkhelp iamthwee ifstream image input int java lib list loop looping loops map math matrix memory multiple newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg simple sorting spoonfeeding string strings struct template templates text tree url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






