c++ problem...having a brainfart (simple math)

Peks

Member
Mar 6, 2003
118
0
0
"Workers at a company have won a 7.6% pay increase retroactive for 6 months. write a program that takes the employee's previous annual salary as input, and outputs the amount of retroactive pay due to the employee."


thats the book's text





ok im taking a c++ class and i need help. the problem asks you to find out a 6 month retroactive pay for a 7.6% increase in salary.



to find that out i need to take the original salary and add on 7.6%...take whatever the amount is after that calculation and divide by 12 to break the yearly increase into monthly salary increases...then multiply by 6 to get a 6 month retroactive pay total? does this sound right? i cant think now for some reason...stupid brain farts.
 

ViRGE

Elite Member, Moderator Emeritus
Oct 9, 1999
31,516
167
106
It would seem to me that if you take the annual salery, and divide it by two, you'll get the amount they originally got paid for the 6 months. You then multiply that by .076, and you have the amount they're owed.

toPay=(annualSalery/2)*.076

There's no need to break the stats down to single months, since the only numbers you're given in the first place are in yearly form.
 

Peks

Member
Mar 6, 2003
118
0
0
i think this is right






//Phil Peklak Page 105 #3 Due: 7/29
#include <iostream>
using namespace std;
int main()

{
double old_salary, retro_salary, new_salary, increase_salary, new_monthly_salary;
char ans;
const double rate = .076;

do
{
cout << "Please enter your old annual salary." << endl;
cin >> old_salary;

new_salary = (old_salary * .076) + old_salary;
increase_salary = new_salary - old_salary;
new_monthly_salary = new_salary / 12;
retro_salary = (old_salary / 2) * rate;

cout << endl;
cout << "Your new annual salary is $";
cout << new_salary << endl;
cout << "You received a $";
cout << increase_salary;
cout << " increase in salary." << endl;
cout << "You will receive $";
cout << retro_salary;
cout << " in retroactive salary." << endl;
cout << "Your new monthly salary is $";
cout << new_monthly_salary << endl;
cout << "Would you like to try this program again?\n";
cin >> ans;
}
while (ans == 'Y' || 'y' == ans);
cout << "Thank you for trying my program, Good-Bye.\n";

return 0;
}
 

ProviaFan

Lifer
Mar 17, 2001
14,993
1
0
That looks right to me, but I haven't run it through a C++ compiler, and I don't have a whole lot of experience with this stuff yet. :)

However, I would suggest telling the user their choices at the menu at the end. If you don't, they might type "Yes" "yes" or "yEs" or any variation of the aforementioned. Your program should be able to gracefully handle situations like that, unless this is just supposed to be a very simple program where you don't need to worry about user-introduced errors.
 

oog

Golden Member
Feb 14, 2002
1,721
0
0
Originally posted by: Peks

to find that out i need to take the original salary and add on 7.6%...take whatever the amount is after that calculation and divide by 12 to break the yearly increase into monthly salary increases...then multiply by 6 to get a 6 month retroactive pay total? does this sound right? i cant think now for some reason...stupid brain farts.

Dividing by 12 then multiplying by 6 is the same thing as just dividing by 2, which is what ViRGE proposed.