0

The Calculation isn't Quite Right

#include <iostream> #include <cmath> #include <string> using namespace std; //getName() string getName(string firstname, string lastname) { string fullname; fullname = firstname + " " + lastname; } float getHours(float Mon, float Tue, float Wed, float Thu, float Fri) { float totalHours; totalHours = Mon + Tue + Wed + Thu + Fri; cout << "Total hours worked: " << totalHours << endl; } float printPay(string fullname, float totalHours) { float hourlyPayRate; float difference, totalPay, totalPayPlusDifference; cout << "Enter hourly pay rate: " << endl; cin >> hourlyPayRate; totalPay = totalHours * hourlyPayRate; if (totalHours > 40) { difference = totalPay * 0.10; totalPayPlusDifference = totalPay + difference; cout << fullname << ", your pay is R" << totalPayPlusDifference << endl; } else if(totalHours < 40) { difference = totalPay * 0.10; totalPayPlusDifference = totalPay - difference; cout << fullname << ", your pay is R" << totalPayPlusDifference << endl; } else cout << fullname << ", your pay is R" << hourlyPayRate << endl; return 0; } int main() { string firstname, lastname,a, c, fullname; float Mon, Tue, Wed, Thu, Fri, totalHours, b; cout << "Enter your first name: " << endl; cin >> firstname; cout << "Enter your last name: " << endl; cin >> lastname; fullname = firstname + " " + lastname; a = getName(firstname, lastname); cout << "Enter the hours you worked for each day of the week (Monday-Friday)" << endl << endl; cout << "Monday: "; cin >> Mon; cout << "Tuesday: "; cin >> Tue; cout << "Wednesday: "; cin >> Wed; cout << "Thursday: "; cin >> Thu; cout << "Friday: "; cin >> Fri; b = getHours(Mon, Tue, Wed, Thu, Fri); c = printPay(fullname, b); return 0; }

17th Sep 2017, 11:33 AM
gorgamin
gorgamin - avatar
4 Réponses
+ 5
Your calculation seems correct, can you show some examples of the input and the output, just to be clear?
17th Sep 2017, 1:59 PM
Ipang
+ 4
@Gorgamin, have you solved this issue? I wrote a fix for your code, comments are added on each changed part, wrote some suggestions also. I only tested on Code Playground editor, but it works there. P.S: Next time please mind code indentation, it's easier to read well indented code :) https://code.sololearn.com/clFSCq3wnd2m/?ref=app
17th Sep 2017, 5:17 PM
Ipang
0
It's supposed to give a 10% bonus if more than 40 hours were worked, and a pay cut of 10% if less than 40 hours were worked.
17th Sep 2017, 11:34 AM
gorgamin
gorgamin - avatar
0
It works if hours = 40, but it gives me the hourly pay rate for more or less than 40.
17th Sep 2017, 2:58 PM
gorgamin
gorgamin - avatar