I'm supposed to grab user input for name, hrs worked, pay rate, and tax bracket: all for four different employees. My code compiles all right, but when it runs, it doesn't wait for the user's name. It outputs like this:
Please enter your full name
Name:
Enter your total hours worked
Then loops endlessly when I enter hours.
Could someone tell me what I'm missing?
(code below)
Code:
#include <iostream.h>
#include <iomanip.h>
#include <string.h>
float gross (float a, float b) //a=hrs, b=rate
{
float r;
r=a*b;
return r;
}
float tax (float c, float d) //c=gross, d=rate
{
float t;
t=c*(d/100);
return t;
}
float net (float e, float f) //e=gross, f=tax
{
float n;
n=e-f;
return n;
}
main()
{
int num;
cout<<"Run Program? (1 for yes, 0 for no)"<<endl;
cin>>num;
while (num=1)
{
//input.......................
float hours;
float taxp;
float rate;
char mybuffer [30];
cout<<"Please enter your full name"<<"\n";
cin.getline (mybuffer,30,'\n');
cout<<"Name: "<<mybuffer<<endl;
cout<<"Enter your total hours worked"<<endl;
cin>>hours;
cout<<"Enter your tax percentage"<<endl;
cin>>taxp;
cout<<"Enter your pay rate"<<endl;
cin>>rate;
//output...............
float z;
z= gross (hours,rate);
cout<<"Gross Pay: "<<gross<<endl;
float y;
y= tax ( z,taxp);
cout<<"Tax Paid: "<<tax<<endl;
//totals.........................
;
}
{
cout<<"Thank you! Please come again!";
return 0;
}
}