Hello again, I've gotten this basic program to work however I'm having difficulties adjusting my output. Why am I unable to output double decimal places?
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
#include "wage.h"
int main()
{
int num2;
float num3;
cout<<"Please enter number of hours worked(-1 to end): ";
cin>>num2;
cout<<"Please enter the rate of pay($00.00): ";
cin>>num3;
Wage objct(num2,num3);
objct.calculateWage();
return 0;
}
I also know about the whole static_cast needed for using different variable types, however at the moment I just wanting to know how to get a decimal output because my setprecision doesn't seem to be effective.
(And sorry if I don't reply immediately currently going to sleep back in 4 hours)
Glad to have you know it's working now. Sorry to bother, but due to my insomnia kicking in and having classes at the University all day I wish to ask for a favour regarding my code. Is it because of me using the "set value" functions that my program doesn't terminate immediately upon entering the flag value? and if so is there anyway I can keep the "setValues" or should I switch to a more basic assignment such as:
1 2 3 4 5 6
Wage::Wage(int num2, double num3)
{
int hours=num2;
double rate=num3;
}
void Wage::calculateWage()
{
cout<<"Please enter hour(s) worked(-1 to end): ";//prime read
cin>>hours;
while (hours!=-1)
{
cout<<"Please enter rate of pay: ";
cin>>rate;
int xhours=hours-40;
float xwage=1.5*xhours;
cout<<fixed<<showpoint;
if(hours>40)
{
grossWage=rate*40+xwage;
cout<<"Salary is $"<<setprecision(2)<<grossWage<<endl;
cout<<"Extra hour(s) worked "<<xhours<<endl;
}
elseif(hours<=40)
{
grossWage=rate*hours;
cout<<"Salary is $"<<setprecision(2)<<grossWage<<endl;
}
cout<<"Please enter hour(s) worked(-1 to end): ";
cin>>hours;
// cout<<"Please enter rate of pay: "; //no need of this one here
// cin>>rate; // no need
}
}