i'm struggling with understanding how to use stringstream objects
i'm working on creating a program to calculate gross and net pay and i'm supposed to calculate both the pays in a function and return it in a stringstream to the main where it is displayed
Code:
#include <iostream>
#include <string>
#include <iomanip>
#include <sstream>
using namespace std;
string AskForName();
double AskForRate(string name);
double AskForHours(string name);
stringstream CalculatePay(double rate, double hours);
int main()
{
cout.setf(ios::fixed);
cout.precision(2);
float rate, hours;
string name;
stringstream pay;
name = AskForName();
rate = AskForRate(name);
hours = AskForHours(name);
pay = CalculatePay(rate, hours);
cout << pay;
system("pause");
return 0;
}
string AskForName()
{
string name;
cout << "\nWhat is your name, good person? \n";
getline (cin, name);
return name;
}
double AskForRate(string name)
{
double rate;
cout << "\nWhat is your hourly rate " << name << "? \n";
cin >> rate;
return rate;
}
double AskForHours(string name)
{
double hours;
cout << "\nHow many hours a week do you work " << name << "? \n";
cin >> hours;
return hours;
}
stringstream CalculatePay(double rate, double hours)
{
double gpay, npay;
stringstream pay (stringstream::in | stringstream::out);
if (hours <= 40)
{
gpay = rate*hours;
}
else if(hours > 40)
{
gpay = ((hours - 40.0)*rate*1.5) + (rate*40.0);
}
if (gpay < 250)
{
npay = gpay;
}
else if( 250 <= gpay <= 500)
{
npay = gpay*.90;
}
else if(gpay > 500)
{
npay = gpay*.80;
}
?????
return pay;
}
i'm not sure how to set up the CalculatePay function to return the stringstream
any help to either that subject or the program in general would be appreciated