Ok, I am creating this program that calculates and displays the amount of annual raises for the next three years, using rates of 2%. 3%, 4% and 5%. The program should end when the user enters a sentinel value as the salary.
Now the code is not allowing me to input a negative number to stop. After it outputs the next 3 years. I input -1 it comes up as "Annual Raises for next three years:" and on the next line it shows me "Press any key to continue....."
Think about your logic: on line 13, you get a salary from the user, and then on 22, you get it again without ever processing the salary you got on line 13! Probably not what you want. Move the logic to get salary from the user from line 22 to the very end of the while loop.
Also, you use a variable RATE in your logic. By convention, a variable that is all caps like RATE is constant or a #define, but you are changing it throughout the program, and never re-initializing it back to the starting value (0.03).
Initially you say you are calculating salaries for 3 years, given percentages 2, 3, 4, and 5%. Isn't that 4 years of raises though?
And to elaborate on why Peter suggested you change the operation from "=" to "<" - when you write salary = 0.0, you aren't testing IF salary is 0, you are assigning the value '0.0' TO salary. To compare, you need to write salary == 0.0.
The code will not stop until you enter the value of salary as -1.
When you enter the salary as -1 , it will come out of loop and execute the line after loop. If nothing is written there , the program will simply exit.
As far as problem is concerned ,do you want to find the final salary after three years when the raise for the first year is 2% , 2nd year is 3% , 3rd year is 4% and so on ? or Have I misunderstood the problem ?
It seems a bit like compound interest problem to me where the salary may be taken as principal , time as 3 years and the rate for each year as 2%,3% and 4% and we have to find amount or compound interest.
You don't actually need to get salary outside the loop. Just initialize it with any value NOT EQUAL TO -1. and you are good to go.