Question on for loops.

Just have a question. I want to recreate this table with any percentage and number however, I looped the years but I also need to loop the number of students each year. How do I do this? For loop into a for loop?.I have calcuated the amount of students by subtracting each two years and found a pattern. How do I loop this? https://imgur.com/a/Mi9Eeqi

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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <iostream>
#include <cmath>
using namespace std;//have to use this for now.
int main(){
	double U,O,F,W,G;
	int count;
	int year;
	int i;
	double offers;
	double declines;
	double withdrawal;
	double graduate;
	double overall_pop;

	cout<<"Enter the current population: ";
	cin>>U;
	cout<<"Enter the % of offer letters: ";
	cin>>O;
	cout<<"Enter the % of offers declined (financial reasons): ";
	cin>>F;
	cout<<"Enter the % of students that withdraw: ";
	cin>>W;
	cout<<"Enter the % of students that graduate: ";
	cin>>G;
		
	cout<<"Year\t\tOffers\t\tDecline\t\tWithdraw\tGraduate\tCurrent Population"<<endl;
	
	
	
	for(i=0;i<100;i=i+1){
	  cout<<"_";
}
cout<<endl;	
	
	for(count=0;count<10;count=count+1){
	year=2009+count;
	
			offers=(O/100)*U;
			declines=(F/100)*offers;
			withdrawal=(W/100)*U;
			graduate=(G/100)*U;
			overall_pop=(offers-declines-withdrawal-graduate)+U;
			
		
			
			
			
			

	cout<<year<<"\t\t "<<offers<<"\t\t"<<declines<<"\t\t"<<withdrawal<<"\t\t"<<graduate<<"\t\t"<<overall_pop<<endl;
	}
	

}
Last edited on
Hello CheesyForde1,

I am guessing that all the numbers in the table are calculated based on the starting population of 12000 and the other information that was entered?

If so than the for loop needs to calculate all the variables before you print out the line.

I would say that you are on the right track, but need more before yo print the line.

Hope that helps,

Andy
Hmm but how do i create different values throughout the years?
Hello CheesyForde1,

I did come up with this, but it still needs some work:

1
2
3
4
5
6
7
8
9
10
11
12
for (count = 0; count < 11; count = count++)
{
	year = 2008 + count;

	if (year > 2008)
	{
		offers = (O / 100.0) * U;
		decline = (F / 100.0) * U;
		withdrawl = (W / 100.0) * U;
		grads = (G / 100.0) * U;
		U *= 1.032;
	}

The last line of the if statement still needs some work because the numbers are not the same as in the link in OP.

Something I was playing with before I had to give up for the night.

Suggestion:

Try this for your headings:
cout << "Year\t\tOffers\t       Decline\t     Withdraw\t      Graduate\t  Current Population" << endl;

The combination of tabs and spaces helps to line up the headings better.

Hope that helps,

Andy
You have to update the current population at the end of each year. To do this, add U = overall_pop; at line 43.
Guys thanks, you solved my problems. I'm not really a problem solver but I thought about this question all day. Really guys I appreciate the help.
Topic archived. No new replies allowed.