Hey guys, I am very new to c++ and I need to write a program that asks the user "How many sheeps do you have?" and "How many generations do you want to wait?". Each generation the sheeps get a 3% increase and a 1% decrease.
(If you were to start with 132 jackalopes, then 3 would be born (132 * 0.03 = 3.96, rounded down to 3) and of the 135, 1 would die, leaving us with 134 jackalopes. The following generation, 3% of the 134 would produce 4 births, and 1% of 138 would produce 1 death, leaving us with 137.)
I know how to do the part where it asks the user for the sheeps and generations, but i dont know how to do the rest. Can someone please help me?
int origpop, gen, newpop;
const int birth = origpop + .03
cout << "How many jackalopes do you have?";
cin >> origpop;
cout << "How many generations do you want to wait?";
cin >> gen;
int year = 0;
newpop = origpop;
do
{
newpop = newpop + .03;
newpop = newpop - .01;
year++;
} while ( year < gen );
cout << "If you start with" << origpop<< "and you wait for" << gen<< "generations, you'll end up with a total of" << newpop<< "of them.";
return 0;
#include <iostream>
usingnamespace std;
int main()
{
int origpop, gen, newpop;
constint birth = origpop + .03
cout << "How many jackalopes do you have?";
cin >> origpop;
cout << "How many generations do you want to wait?";
cin >> gen;
int year = 0;
newpop = origpop;
do
{
newpop = newpop + .03;
newpop = newpop - .01;
year++;
} while ( year < gen );
cout << "If you start with" << origpop<< "and you wait for" << gen<< "generations, you'll end up with a total of" << newpop<< "of them.";
return 0;
Follow the program from top to bottom, as a computer would: Line 7 declares a variable, origpop. It is not defined at this point and its value is most likely random. Line 8 adds .03 to the undefined value and stores it in birth. Line 10 stores a user-entered value in origpop. These statements are not in the appropriate order.
Additionally, integers are signed whole numbers. You might want to use a float or double to store any value that should contain a decimal portion.