this is the excercise
Suppose that the tuition for a university is $10,000 this year (year 1) and increases
5% every year. Write a program that computes the tuition in x years from now, with
x being a number given by the user. In addition, the program should compute the
total cost of y years’ worth of tuition starting from now, with y being a number given
by the user. Finally, the program should display the tuition for x years along with the total tuition cost at the end of each year. Your program will terminate when the user
enters 0.
the output should look like that >>
Welcome to the tuition calculator!
1 Compute the yearly tuition in x years from today
2 Compute the total tuition cost for y years from today
3 Compute yearly tuition and total tuition cost at the end of each year, for x years
0 Quit program
Enter choice: 1
You want to know the yearly tuition in how many years from today? 2
The yearly tuition after 2 years from today will be 11025
Enter choice: 2
You want to know the total tuition cost after how many years from today? 2
The total tuition cost after 2 years from today will be 20500
Enter choice: 3
How many years you want to consider starting from today? 3
Year Tuition Total Tuition Cost at the End of Year
1 10000 10000
2 10500 20500
3 11025 31525
Enter choice: 0
Goodbye!
it shouldnt ask "enter choice" all the time. Its just to show what it wants with each number chosen.
Here is my code. I dont know how do i count the second choice and have no idea what to do for the third choice either.
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
|
#include <iostream>
using namespace std;
int main()
{
double tuition = 10000;
double total;
int a;
cout << "Welcome to the tuition calculator!" << endl;
cout << "1 Compute the yearly tuition in x years from today " << endl;
cout << "2 Compute the total tuition cost for y years from today" << endl;
cout << "3 Compute yearly tuition and total tuition cost at the end of each year, for x years " << endl;
cout << "0 Quit program " << endl << endl;
cout << "Enter your choice: ";
cin >> a;
if (a == 1) {
cout << "You want to know the yearly tuition in how many
years from today? ";
int b;
cin >> b;
for (int i = 1; i <= b; i++) {
tuition = tuition * .05 + tuition;
}
cout << "The yearly tuition after " << b << " years from today will be " << tuition;
}
else if (a == 2) {
cout << "You want to know the total tuition cost after how many years from today? ";
int c;
cin >> c;
for (int z = 1; z <= c; z++) {
tuition = tuition + (tuition * .05 + tuition);
}
cout << "The total tuition cost after " << c << " years from today will be " << tuition;
}
}
|
I know only loops,else if and thats pretty much it. So please keep it the same simple style so i can understand your code. Thank you very much