#include <iostream>
#include <iomanip>
usingnamespace std;
int main()
{
//declare variables
int year = 0;
double salary = 0.0;
double raise = 0.0;
double totalSalary = 0.0;
constdouble rate = 1.05;
//Enter Salary
cout << "Enter Annual Salary: $ " ;
cin >> salary;
while (int year = 1; year < 4; year += 1)
{
raise = salary * rate;
salary += raise;
totalSalary += salary;
}//end while
cout << "Year: " year << "Raise:$ " << raise << endl;
cout << fixed << setprecision(2);
cout << "Total salary for the three years:$ " << totalSalary << endl;
system("pause");
return 0;
} //end of main function
The problem is Effective January 1st of each year, I reveive a 5% raise on my previous year's salary. I want a program that calculates and displays the amount of my annual raises for the next three years. The program also should caclualte and display my total salary for the three years.
You say that your yearly raise is 5%, but you set that variable to 105%. constdouble rate = 1.05;
You loop through the 3 years, calculating the raise and salary for each year, so why not display the results in the same loop?
There is also a scope issue with int year;
sorry for being so cryptic; this seems like a homework problem so I don't want to just give out the answer.
looks like either make rate = . 05, OR in line 21: salary=salary*rate...
right now you have it taking your current salary *1.05.. this would calculate your new salary, not the raise.. the raie itself would be just salary* .05..hope that helps :D