• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

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

Peks

Member
"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.
 
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.
 
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;
}
 
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.
 
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.
 
Back
Top