Need Help computing tuition!

The question is: Suppose that the tuition for a university is $10,000 this year and increases 5% every year. Write a program that computes the tuition in ten years and the total cost of four years' worth of tuition starting ten years from now.

The correct answers to this program should be:

The tuition after 10 years is $16288.9
Tuition in year 1 is $16288.9
Tuition in year 2 is $17103.4
Tuition in year 3 is $17958.6
Tuition in year 4 is $18856.5
4 year total tuition is $70207.4

I have wrote the first part of the program but am not sure how to go from here. Any help is appreciated! This is what I have so far:


#include<iostream>
using namespace std;

int main ()
{
double tuition = (10000);
int year = 1;

for (int i = 1; i <= 10; i++)
{
tuition = ((tuition * .05) + tuition);

}
cout << "Tuition after 10 years is: " << tuition << endl;

return 0;
}
Here's a hint:

double tuition = 16288.9

I am not sure whether this is what you need for the assignment. If it is not, maybe it is something similar to what I wrote. PLEASE NOT TO BE plagiarized. Try to look through what I have, and then write your own codes.


int main ( )
{	
                const double tuition = 16288.9;
	int year = 4;

	cout << "The tuition after 10 years is $ " << tuition << endl;


	double total = 0;
	double yearTuition = 0;
	for (int i = 1; i <= year; i++)
	{	
		switch (i)
		{
		case 1: cout << "Tuition in year 1" << " is $ " << tuition << endl;
				break;
		case 2: yearTuition = ((tuition * .05) + tuition);
				cout << "Tuition in year 2" << " is $ " << yearTuition << endl;
				break;
		case 3: yearTuition = ((yearTuition * .05) + yearTuition);
				cout << "Tuition in year 3" << " is $ " << yearTuition << endl;
				break;
		case 4: yearTuition = ((yearTuition * .05) + yearTuition);
				cout << "Tuition in year 4" << " is $ " << yearTuition << endl;
				break;
		}
		
		total = total + yearTuition;
		}
	total += tuition;
	cout << "4 year total tuition is $ " << total << endl;
	
	system ("pause");
	return 0;
}





The tuition after 10 years is $ 16288.9
Tuition in year 1 is $ 16288.9
Tuition in year 2 is $ 17103.3
Tuition in year 3 is $ 17958.5
Tuition in year 4 is $ 18856.4
4 year total tuition is $ 53918.3
Press any key to continue . . .
Last edited on
Thanks for the help! I am still having trouble coming out with the right 4 year amount I am getting 72,858.4 and the answer should be 70,207.4 I not sure what i am doing wrong. I need help fixing this formula to calculate the right amount.

}

total = total + yearTuition * 3;
}

total += tuition;

cout << "4 year total tuition is $ " << total << endl;

closed account (DSLq5Di1)
The above code soulMonk posted gave me the correct total, so I'm not really sure why you have a different value..

Here is my own take on your problem using a compound interest formula:-

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
#include <iostream>
using namespace std;

inline double compound_interest(double presentValue, double interestRate, int years)
{
	return presentValue * pow(1 + interestRate, years);
}

int main()
{
	const double interest = 0.05;
	double total = 0, tuition = compound_interest(10000, interest, 10);
	
	cout << "The tuition after 10 years is $" << tuition << endl;

	for (int i = 0; i <= 3; i++)
	{
		double futureValue = compound_interest(tuition, interest, i);
		cout << "Tuition in year " << i+1 << " is $" << futureValue << endl;

		total += futureValue;
	}

	cout << "4 year total tuition is $" << total;

	cin.sync();
	cin.ignore();

	return 0;
}
This is what I got, it might be wrong.

1
2
3
4
5
6
7
8
9
int main() {

	double starttuition = 10000*1.05*1.05*1.05*1.05*1.05*1.05*1.05*1.05*1.05*1.05;

	totaltuition = starttuition + (starttuition*1.05) + (starttuition*1.05*1.05) + (starttuition*1.05*1.05*1.05);

	cout<<"Total tuition is "<<totaltuition;

	return 0;}

Topic archived. No new replies allowed.