Help Me with this code

Please help me with this code, its just showing me blank output.

The program is to calculate how long it will take a university to have a population of 10,000 if they start with 200
students and increase at the ratio of 20% per annum.

#include <iostream>
using namespace std;
int main ()
{
int count, p;
for(int p=200; p<=10000; p++) //where p is the population
p = 200 + ((200/100) * 20);
count += p;
Cout << count;
return 0;
}
You need to initialize count to an initial value.

Please use the code tags next time when you post your code. :)
Just do this. Easy fix :)

1
2
3
4
5
6
7
8
9
10
11
12
#include <iostream>
using namespace std;
int main ()
{
int count=0;
int p;
for(int p=200; p<=10000; p++) //where p is the population
p = 200 + ((200/100) * 20);
count += p;
cout << count;
return 0;
}
Last edited on
Make sure not to capitalize cout.
Have correct all those errors. Its the same thing. Please what shoul I do.
int count=0, p;
You did that?
closed account (D80DSL3A)
um...small problem with the for loop:
1
2
for(int p=200; p<=10000; p++)
    p = 240;

p will never reach 10001 (because line 2 keeps resetting the value to 240) so the loop will never end.
Last edited on
This should Help, I re-wrote it, Let me know if it helps. You Should be able to answer this. It's basic college algebra.....I took algebra last year in college...........

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// Calulating Population growth == Time
#include <iostream>
#include <cmath> // for calculation
using namespace std;

int main ()
{
	
	double Total_Years;
	double Total_Pop = 10000;	// Final Population
	double Pop = 200;			// Intital Population
	double Growth_Rate = 0.20;	// == 20 Percent.
	double XY;

	XY = log (Total_Pop / Pop);
	Total_Years = XY / Growth_Rate;

//      Another way to write would be 
//      Total_Years = (log (Total_Pop / Pop)) / Growth_Rate;

//      Both Gives the Same Answer

	cout << Total_Years << "\n" << endl;
	return 0;
	
}




19.5601

Press Any Key to Continue......

Last edited on
Still doesn't work
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <iostream>
using namespace std;
int main ()
{
int count=0;
int p =200 + ((200/100) * 20);
for(int counter=0; counter<=(10000-201); counter++) 
{
p = p +200 + ((200/100) * 20);

cout << p << " ";
}
return 0;
}



it will work :D
Last edited on
tried ?
Topic archived. No new replies allowed.