C++ code is not working would someone please help me understand?

This is what I have and it is not working properly.
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
#include <iostream>
 #include <iomanip>
 
using namespace std;
 int main()
 {
 //declare variables
 
int year = 0;
 double salary = 0.0;
 double raise = 0.0;
 double totalSalary = 0.0;
 const double 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.

PLEASE HELP!
You say that your yearly raise is 5%, but you set that variable to 105%.
const double 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
cout<<"Year: "<< year<<"Raise:$ "<<raise<<endl;
Topic archived. No new replies allowed.