Please someone help me, I'm supposed to come up with a C++ code to give the following dialog (user input capable text is in BOLD) I'm supposed to have one loop for full credit... but I'm not even concerned with that if I'm able to make this work some other way....what I have done so far is below and it's driving me nuts (I told you...I'm a total newbie!) :-D
I only have till midnight today!! Please someone help me out, I'll study it an learn it better then fighting with it all day and failing the challenge
(with the understanding that during
boom times, population increases by 15%. During bad times,
population decreases by 20%)
This is the desired dialog when the program is Run:
Enter a starting population size: 1000
After a boom year, your population has grown to:1150
After a bad year, your population has shrunk to:800
Continue(y/n)? y
Was it a boom or bad year (o/a)? o
Your starting population is now 1150
After a boom year, your population has grown to:1323
After a bad year, your population has shrunk to:920
Continue(y/n)? y
Was it a boom or bad year (o/a)? a
Your population is now 920
After a boom year, your population has grown to:1058
After a bad year, your population has shrunk to:736
Continue(y/n)? n
Was it a boom or bad year (o/a)? o
Your final population is 1058
I only have till midnight today!! Please someone help me out, I'll study it an learn it better then fighting with it all day and failing the challenge
(with the understanding that during
boom times, population increases by 15%. During bad times,
population decreases by 20%)
This is the desired dialog when the program is Run:
Enter a starting population size: 1000
After a boom year, your population has grown to:1150
After a bad year, your population has shrunk to:800
Continue(y/n)? y
Was it a boom or bad year (o/a)? o
Your starting population is now 1150
After a boom year, your population has grown to:1323
After a bad year, your population has shrunk to:920
Continue(y/n)? y
Was it a boom or bad year (o/a)? a
Your population is now 920
After a boom year, your population has grown to:1058
After a bad year, your population has shrunk to:736
Continue(y/n)? n
Was it a boom or bad year (o/a)? o
Your final population is 1058
Code:
#include <iostream>
using namespace std;
int main()
{
double population = 0;
double boom_year;
double bad_year;
char contin;
char boomornot;
cout << "Enter a starting population size: ";
cin >> population;
boom_year = (population * 1.15);
bad_year = (population * 0.8);
cout << "After a boom year, your population has grown to: " << boom_year << "\n";
cout << "After a bad year, your population has shrunk to: " << bad_year << "\n";
cout << "Continue(y/n)? "; // determines which IF statement below to acccess
cin >> contin;
if (contin == 'n') // I'm pretty confident with this section, it displays final result and then exits
{
cout << "Was it a boom or BAD year (o/a)? ";
cin >> boomornot;
if (boomornot == 'o')
{
population = boom_year;
cout << "Your final population is " << boom_year << "\n";
}
if (boomornot == 'a')
{
population = bad_year;
cout << "Your final population is " << bad_year << "\n";
}
}
if (contin == 'y') // this section is a mess...it works, but can't loop and can't figure it out otherwise...HELP!
{
cout << "Was it a BOOM or bad year (o/a)? ";
cin >> boomornot;
if (boomornot == 'o')
{
population = boom_year;
cout << "Your starting population is now " << boom_year << "\n";
}
if (boomornot == 'a')
{
population = bad_year;
cout << "Your starting population is now " << bad_year << "\n";
}
}
// need more code probably....can someone brilliant help me out??
return 0;
}