diff options
| author | WiserJ <[email protected]> | 2021-10-20 16:21:50 -0700 |
|---|---|---|
| committer | WiserJ <[email protected]> | 2021-10-20 16:21:50 -0700 |
| commit | 2b15130b56dae3aab6d3c93a968e5e94d2e4929c (patch) | |
| tree | e9c07bb5436d5fb0519d8056f9b468b18a003243 | |
| parent | average program v2 (diff) | |
| download | cst116-lab4-jeffwoit-2b15130b56dae3aab6d3c93a968e5e94d2e4929c.tar.xz cst116-lab4-jeffwoit-2b15130b56dae3aab6d3c93a968e5e94d2e4929c.zip | |
salary program v1
| -rw-r--r-- | CST116F2021-Lab4/CST116F2021-Lab4.cpp | 121 |
1 files changed, 88 insertions, 33 deletions
diff --git a/CST116F2021-Lab4/CST116F2021-Lab4.cpp b/CST116F2021-Lab4/CST116F2021-Lab4.cpp index decdaa0..5979260 100644 --- a/CST116F2021-Lab4/CST116F2021-Lab4.cpp +++ b/CST116F2021-Lab4/CST116F2021-Lab4.cpp @@ -5,42 +5,97 @@ using namespace std; -float average(int, int, int, float); +void GetInput(float& salary, int& years_service); +void CalcRaise(float& salary, int years_service); +int CalcBonus(int years_service); +void PrintCalculations(int years_service, float salary, int bonus); int main() { - float avg = 0; - int input1 = 0, input2 = 0, input3 = 0; - - do - { - avg = average(input1, input2, input3, avg); - } while (avg == 0); - - cout << "The average of these values is " << avg; + int years_service = 0, bonus = 0; + float salary = 0.0; + + GetInput(salary, years_service); + CalcRaise(salary, years_service); + bonus = CalcBonus(years_service); + PrintCalculations(years_service, salary, bonus); +} + +void GetInput(float& sal_input, int& years_service_input) +{ + do + { + cout << "Please input the salary: "; + cin >> sal_input; + } while (sal_input <= 0); + + do + { + cout << "Please input the years of service: "; + cin >> years_service_input; + } while (years_service_input <= 0); +} + +void CalcRaise(float& sal_raise, int years_service) +{ + if (years_service > 10) + sal_raise *= 1.1; + else if (years_service <= 10 && years_service >= 5) + sal_raise *= 1.05; + else + sal_raise *= 1.02; +} + +int CalcBonus(int years_service) +{ + int bonus = 0; + + bonus = (years_service / 2) * 500; + return bonus; } -float average(int input1, int input2, int input3, float avg) +void PrintCalculations(int years_service, float salary, int bonus) { - do - { - cout << "Please input the first value: "; - cin >> input1; - } while (input1 <= 0); - - do - { - cout << "Please input the second value: "; - cin >> input2; - } while (input2 <= 0); - - do - { - cout << "Please input the third value: "; - cin >> input3; - } while (input3 <= 0); - - avg = (input1 + input2 + input3)/3; - - return avg; -}
\ No newline at end of file + cout << "Due to your " << years_service << "years of service, your new salary is $" << salary << " and your bonus is $" << bonus << ".\n"; +} + + +//pg.207 +//float average(int, int, int, float); +//int main() +//{ +// float avg = 0; +// int input1 = 0, input2 = 0, input3 = 0; +// +// do +// { +// avg = average(input1, input2, input3, avg); +// } while (avg == 0); +// +// cout << "The average of these values is " << avg; +//} +// +//float average(int input1, int input2, int input3, float avg) +//{ +// do +// { +// cout << "Please input the first value: "; +// cin >> input1; +// } while (input1 <= 0); +// +// do +// { +// cout << "Please input the second value: "; +// cin >> input2; +// } while (input2 <= 0); +// +// do +// { +// cout << "Please input the third value: "; +// cin >> input3; +// } while (input3 <= 0); +// +// avg = (input1 + input2 + input3)/3; +// +// return avg; +//}
\ No newline at end of file |