Writing a salary algorithm, completely new to this

I am trying to write an algorithm to calculate salary, that will receive a 3% raise every year.  If making $20,000 this year, the salary next year would be $20,600 ($20,000 + ($20,000)*.03)) and $21,218 the year after ($20,600 + ($20,600 * .03)), $21,854.54 the year after ($21,218 + ($21,218 * .03)), etc. I want to do this up to $30,000.

I want to write it so I can compute for a salary of 30k after any number of years.


Here is some code I wrote that is completely wrong which is why I am seeking help.

#include <iostream>
using namespace std;
int main()
{
const float t = 1;
float money, radius = 11, salary = 20.0*(1+0.03)^t,
cout << "yearly_income = " << salary <<endl;
cin.get ();
return 0;
}
Last edited on
If you want it to go up to $30,000, use a loop that stops once it reaches that value. For example...
1
2
3
4
5
6
salary = 20000;

while (salary < 30000)
{
    salary *= 1.03;
}


Last edited on
I really need some explaining on this.
Last edited on
I have no idea what you're doing in your last post. You're saying you want to do it up to $30,000, so just use a loop.
i used your example and I received these errors:

salary.cpp:1:1: error: ‘salary’ does not name a type
salary.cpp:3:1: error: expected unqualified-id before ‘while’

Ignore my last post, it was something way different, this is only my first week programming so some kindergarten like steps would be much appreciated!
Do you know about loops like the one I showed? Post the complete code that gave you those errors.
No I do not know about loops, did you mean for me to post your loop into the code I had already? I'm totally lost here
You might find it useful to write out your methodolgy as comments, then go back and write th code.

This can be done incrementally - so write a few general ideas, then go back and insert more detail. When you are happy, write the code - leave the comments as they form documentation.

To make it easy to start with - hard code the values (put the values into the code) - when that is working, change it so that it asks for input from the user.

So you need to think about which variables you need and their types (double would be good)

Next a formula to calculate the answer - freddy92 provided a big clue.

Most importantly - you need to do a lot of reading. There is the reference section - top left of this page. There is Google & Wiki. Also try the first 4 chapters of this book - will give a good idea on the basics:

http://zanasi.chem.unisa.it/download/C.pdf


This stuff is really old (1984) but is written by the guys who invented the C language and is a really good refernce IMO.

HTH
Topic archived. No new replies allowed.