Strings and paramaters

I need the following program to run the functions I wrote.I struggle to remember how to let the printPay() get the variable fullname(struggle with strings).
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <iostream>
#include <string>

using namespace std;
// Calculates the pay , if toatlhours >40 +10& bonus but if <40 deduct 10%
float printPay(float totalhours, std::string fullname){

    float constRate=120.35;
    int bonus= 10;
    float pay=totalhours*constRate;
    float bonusamout=bonus*pay/100;
    float finalpay;

    if (totalhours >40){
    ;
    finalpay=bonusamout + pay;
    cout<< fullname << "recieves a bonus of R" << bonusamout <<"that is included in total pay for week :R" << finalpay << endl;}
    else if (totalhours==40){
    finalpay=pay;
    cout<< fullname << "gets total pay for week :R" << finalpay<< endl;}
    else {

    finalpay=pay-bonusamout;
    cout<< fullname << "gets R"<< bonusamout<< "deducted from total pay for week :R" << finalpay<< endl;}
    }

// Calculate the total of hours worked in a week and reutn totalhours
float getHours(){
    int mhours;
    int thours;
    int whours;
    int tThours;
    int fhours;

cout << "How many hours did the employee work on Monday?"<< endl;
cin >> mhours;
cout << "How many hours did the employee workwork on Tuesday?"<< endl;
cin >> thours;
cout << "How many hours did the employee workwork on Wensday?"<< endl;
cin >> whours;
cout << "How many hours did the employee workwork on Thursday?"<< endl;
cin >> tThours;
cout << "How many hours did the employee workwork on Friday?"<< endl;
cin >> fhours;

float totalhours=mhours+thours+whours+tThours+fhours;
return totalhours;
}
//Function to combine first name and last name return fullname
std::string  getName()
{
    std::string fname;
    std::string sname;
cout<< "What is the employees first name"  << endl;
cin >> fname;
cout << "what it the employess last name" << endl;
cin>> sname;
std::string  fullname=fname+" "+sname;

return fullname;
}

main(){
std::string fullname;
float totalhours;
getName();
getHours();
printPay(totalhours,fullname);
return 0;}
63
64
65
66
67
68
69
main(){
std::string fullname;
float totalhours;
std::string fullname = getName();
float totalhours = getHours();
printPay(totalhours,fullname);
return 0;}
Last edited on
Topic archived. No new replies allowed.