C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old November 10th, 2012, 09:37 PM
Java the Script Java the Script is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 2 Java the Script User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 10 m 56 sec
Reputation Power: 0
Help with decimals

I need help figuring out what is wrong with my code. I've included my code - the output it displays and what it is suppose to display.

MY CODE:

Code:
#include <iostream>
#include <iomanip>

using namespace std;

double populationSize(double P, double B, double D, double A, double M);

int main() {
double populationStart;
double annualB;
double annualD;
double peopleA;
double peopleM;
double result;
int nYears;

cout<<"This program calculates population change.\n";
cout<<"Enter the starting population size: ";
cin>>populationStart;
if(populationStart < 2) {
cout<<"\nStarting population must be 2 or more.";
cout<<"\nPlease re-enter:";
cin>>populationStart;
}
cout<<"Enter the annual birth rate (as % of current population):";
cin>>annualB;
if(annualB < 0) {
cout<<"\nBirth rate percent cannot be negative.";
cout<<"\nPlease re-enter:";
cin>>annualB;
}
cout<<" Enter the annual death rate (as % of current population):";
cin>>annualD;
if(annualD < 0) {
cout<<"\nDeath rate percent cannot be negative.";
cout<<"\nPlease re-enter:";
cin>>annualD;
}
cout<<" How many individuals move into the area each year? ";
cin>>peopleA;
if(peopleA < 0) {
cout<<"\nArrivals cannot be negative.";
cout<<"\nPlease re-enter:";
cin>>peopleA;
}
cout<<"How many individuals leave the area each year? ";
cin>>peopleM;
if(peopleM < 0) {
cout<<"\nDepartures cannot be negative.";
cout<<"\nPlease re-enter:";
cin>>peopleM;
}
cout<<"For how many years do you wish to view population changes? \n";
cin>>nYears;
if(nYears < 1) {
cout<<"\nYears must be one or more.";
cout<<"\nPlease re-enter:";
cin>>nYears;
}

cout<<"\nStarting population: "<<populationStart<<"\n";
result = populationStart;
for(int y = 1; y < nYears; y++) {
result = populationSize(result, annualB, annualD, peopleA, peopleM);
cout<<"\n";
cout<< showpoint << setprecision(3) << "Population at the end of year "<<y<<" is "<<result;
}

return 0;
}

double populationSize(double P, double B, double D, double A, double M) {
double n;

n = P + (B/100 * P) - (D/100 * P) + A - M;

return n;
}


EXPECTED OUTPUT:

This program calculates population change.
Enter the starting population size: Enter the annual birth rate (as % of current population): Enter the annual death rate (as % of current population): How many individuals move into the area each year? How many individuals leave the area each year? For how many years do you wish to view population changes?

Starting population: 100

Population at the end of year 1 is 103.
Population at the end of year 2 is 107.
Population at the end of year 3 is 111.
Population at the end of year 4 is 114.
Population at the end of year 5 is 118.
Population at the end of year 6 is 122.
Population at the end of year 7 is 125.
Population at the end of year 8 is 129.
Population at the end of year 9 is 132.
Population at the end of year 10 is 136.


ACTUAL OUTPUT:

This program calculates population change.
Enter the starting population size: Enter the annual birth rate (as % of current population): Enter the annual death rate (as % of current population): How many individuals move into the area each year? How many individuals leave the area each year? For how many years do you wish to view population changes?

Starting population: 100

Population at the end of year 1 is 104.
Population at the end of year 2 is 107.
Population at the end of year 3 is 111.
Population at the end of year 4 is 115.
Population at the end of year 5 is 118.
Population at the end of year 6 is 122.
Population at the end of year 7 is 126.
Population at the end of year 8 is 129.
Population at the end of year 9 is 133.

Reply With Quote
  #2  
Old November 11th, 2012, 11:13 AM
Java the Script Java the Script is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 2 Java the Script User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 10 m 56 sec
Reputation Power: 0
Well that wasn't very helpful

Reply With Quote
  #3  
Old November 12th, 2012, 04:06 AM
ericagodwin ericagodwin is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 4 ericagodwin User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 m 24 sec
Reputation Power: 0
thank you for look..URLURLURLURL

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > Help with decimals


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.

© 2003-2014 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap