problems with for command

Hello, this is my assignment:

Write a program that will predict the size of a population of organisms. The program should ask the user for the
starting number of organisms, their average daily population increase (as a percentage), and the number of days they
will multiply. A loop should display the size of the population for each day.
Input Validation: Do not accept a number less than 2 for the starting size of the population. Do not accept a negative
number for average daily population increase. Do not accept a number less than 1 for the number of days they will
multiply.

My code works fine just up until the end, and i was hoping one of you would be able to find my problem.

#include <iostream>
using namespace std;

int main()
{
int organisms = 0, growthRate, rate, days, amount = 0;
//int x; //for loop

//user enters number of organisms
cout << "Please enter the initial number of organisms: ";
cin >> organisms;

//if user enters less than 2
while (organisms < 2)
{
cout << "Please enter a number greater than or equal to 2: ";
cin >> organisms;
}

//user enters growth rate
cout << "Please enter the growth rate of the organisms: ";
cin >> rate;

//if user enters a negative number
while (rate < 0)
{
cout << "Please enter a positive rate: ";
cin >> rate;
}

//user enters the amount of days
cout << "Please enter the amount of days the organisms grow: ";
cin >> days;

//if the user enters less than 1 day
while (days < 1)
{
cout << "Please enter a number greater than or equal to 1 :";
cin >> days;
}

//Calculate growth rate
growthRate = rate / 100;

//start calulation loop
//x = 0; //for loop

for (int x = 0; days <= x; x++)
{
organisms = (organisms*growthRate) + organisms;
cout << x << "---> " << organisms << ".\n";

}

system("pause");
return 0;

}
Last edited on
Please put your code in code tags:

[code]Put your code between these tags[/code]


Also...
My code works fine just up until the end, and i was hoping one of you would be able to find my problem.


Can you please be more descriptive? "It doesn't work" doesn't tell us much.

- What input are you giving it?
- What output are you expecting?
- What output are you getting?
Topic archived. No new replies allowed.