0

Why is this not outputting anything?

#include <iostream> using namespace std; string getName() { string name, surname; cout<<"Please enter your first name....."; cin>>name; cout<<"Please enter your last name....."; cin>>surname; return name+' '+surname; } float getHours(string theName, float theRate) { float grossPay, nettPay; int hours, totalHours=0; cout<<"Please enter number of hours worked for Monday....."; cin>>hours; totalHours+=hours; cout<<"Please enter number of hours worked for Tuesday....."; cin>>hours; totalHours+=hours; cout<<"Please enter number of hours worked for Wednesday....."; cin>>hours; totalHours+=hours; cout<<"Please enter number of hours worked for Thursday....."; cin>>hours; totalHours+=hours; cout<<"Please enter number of hours worked for Friday....."; cin>>hours; totalHours+=hours; grossPay=theRate*totalHours; if(totalHours<40) nettPay=grossPay-(grossPay*0.10); else if(totalHours>40) nettPay=grossPay+(grossPay*0.10); else nettPay=grossPay; return nettPay; } int main() { string fullName; float pay; fullName=getName(); pay=getHours(fullName, 80.00); cout.setf(ios::fixed); cout.precision(2); cout<<"Employee "<<fullName<<" is paid : R"<<pay<<endl; return 0; }

17th Sep 2017, 10:20 AM
gorgamin
gorgamin - avatar
3 Réponses
+ 1
where are calling your method
17th Sep 2017, 12:17 PM
Joshua
Joshua - avatar
0
Write a program that demonstrates the use of the following functions. A C++ function named getName()prompts the user for two string values; first name and last name and return a combination of the two as one value. The second function getHours()calculate employee’s weekly pay, it must receive one argument, fullName, a string variable and a float value for the rate. It must then prompt the user for hours worked for each day of the week, i.e. Monday – Friday and calculates the weekly pay. Employees who have worked more than 40 hours that week will receive a bonus of 10% and those who have worked less than 40 hour will receive 10% less pay for that week.
17th Sep 2017, 10:20 AM
gorgamin
gorgamin - avatar
0
I have it like this now, but the calculations aren't correct. #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) { totalPayPlusDifference = totalPay + (totalPay * 1.10); cout << "totalPay is " << totalPay << endl; 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, 12:19 PM
gorgamin
gorgamin - avatar