View Single Post
Old 03-20-2005, 09:28 PM   #3 (permalink)
cleverest
 
Newb Techie

Join Date: Mar 2005

Posts: 2

cleverest

Send a message via AIM to cleverest
Default added additional problem I've found

Actually I believe this will be VERY helpful, I'm going to try to work on what you said....

Since I've typed that sentence above this one, I've managed to write this code, and its VERY CLOSE...any suggestions anyone, to get it to resemble the program dialog in my first post up top?


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)? "; 
	cin >> contin;

	while (contin == 'y')
	{
    cout << "Was it a BOOM or bad year (o/a)? ";
		cin >> boomornot;
		if (boomornot == 'o')
	    {
		population = boom_year;
		cout << "Your starting population has grown to " << boom_year << "\n";
	    }
			if (boomornot == 'a')
	        {
		population = bad_year;
		cout << "Your starting population has shrunk to " << bad_year << "\n"; 
	        }
	cout << "Continue(y/n)? "; 
	cin >> contin;
	}

	 if (contin == 'n') 
		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";
		}
	    


}
Also the program dialog that exists with the above program I've written is as follows and it doesn't match the goal exactly which is shown in the first post.....can anyone help? (I'm such a newbie but I'm learning!)

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 has grown to 1150
Continue(y/n)? y
Was it a BOOM or bad year (o/a)? a
Your starting population has shrunk to 800
Continue(y/n)? n
Was it a boom or BAD year (o/a)? o
Your final population is 1150
Press any key to continue
cleverest is offline