Narue ROCKS!!! but need one last thing???

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Oct 2004
Posts: 18
Reputation: hill0ster is an unknown quantity at this point 
Solved Threads: 0
hill0ster hill0ster is offline Offline
Newbie Poster

Narue ROCKS!!! but need one last thing???

 
0
  #1
Oct 17th, 2004
Narue, thanks for all your help with this program! I really appreciate it. I have one last problem. In the function tryAgain, if user presses 'q' or 'Q'; the program terminates. No problem there, but if they hit anyother key; the program should allow them to re-enter pyrllSt (payroll status again). I don't believe I am getting into the second part of the if statement in the tryAgain function... Any suggestions? By the way the double suggestion works perfectly. You are one smart cookie. Thank you!

#include <iostream>
using namespace std;
#include <cstdlib>
#include <string>

bool getEmployeeData (int*, char*, double*, double*, double*, double);
float calculateGrossPay (char, double, double, double);
void displayEmployeeInfo(int, char, double);
bool tryAgain(char*);
bool isValidStatus(char*);

int main()
{
int ID = 0;
double Salary = 0;
double hourwrk = 0;
double sales = 0;
double grossPay = 0;
char pyrllSt = ' ';
float totalPayroll = 0.0;
bool result = true;
while (result)
{
result = getEmployeeData (&ID, &pyrllSt, &Salary, &hourwrk, &sales, totalPayroll);
if (result)
{
grossPay = calculateGrossPay(pyrllSt, Salary, hourwrk, sales);
totalPayroll += grossPay;
displayEmployeeInfo (ID, pyrllSt, grossPay);
}
else
{
cout << "Total Payroll for this month: " << endl;
cout << totalPayroll << endl;
}
}
return (1);
}

bool getEmployeeData (int *ID, char *pyrllSt, double *Salary, double *hourwrk, double *sales, double totalPayroll)
{
cout << "Enter employee ID: " << endl;
cin >> *ID;

if (*ID > 0)
{
cout << "Enter payroll status: " << endl;
cin >> *pyrllSt;
if (isValidStatus(pyrllSt))
{
if (*pyrllSt == 's' || *pyrllSt == 'S')
{
cout << "Enter monthly salary" << endl;
cin >> *Salary;
}

if (*pyrllSt == 'h' || *pyrllSt == 'H')
{
cout << "Enter number of hours worked this month: " << endl;
cin >> *hourwrk;
}

if (*pyrllSt == 'c' || *pyrllSt == 'C')
{
cout << "Enter total sales for this month: " << endl;
cin >> *sales;
}
}//if isValid Status
return true;
}
else
{
return false;
}
}

bool isValidStatus (char *pyrllSt)
{
bool isGood = true;

while (isGood)
{

isGood = (*pyrllSt == 's' || *pyrllSt == 'S' || *pyrllSt =='h' || *pyrllSt == 'H' || *pyrllSt == 'c' || *pyrllSt =='C');

if (isGood)
{
return true;
}
else
{
isGood = tryAgain(pyrllSt);
}
}
return false;
}

bool tryAgain(char *pyrllSt)
{
char quit;

cout << "Type Q or q to quit, any other key to continue: " << endl;
cin >> quit;

if (quit == 'q' || quit == 'Q')
{
cout << "*** Program Terminated ***" << endl;
return false;
}
else
{
cout << "Re-enter: 's' or 'S' for salaried, 'h' or 'H' for hourly, " << endl;
cout << "'c' or 'C' for commissioned." << endl;
cin >> *pyrllSt;
return true;
}
}

float calculateGrossPay (char pyrllSt, double Salary, double hourwrk, double sales)
{
float grossPay;
if (pyrllSt == 's' || pyrllSt == 'S')
{
grossPay = Salary;
}

if (pyrllSt == 'h' || pyrllSt == 'H')
{
grossPay = hourwrk * 18.75;
}

if (pyrllSt == 'c' || pyrllSt == 'C')
{
grossPay = sales * 0.06 + 1000.00;
}
return grossPay;

}

void displayEmployeeInfo (int ID, char pyrllSt, double grossPay)
{
cout << "Employee ID: " << ID << endl;
cout << "Payroll Status: " << pyrllSt << endl;
cout << "Gross Pay: " << grossPay << endl;
}
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,625
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 716
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: Narue ROCKS!!! but need one last thing???

 
0
  #2
Oct 17th, 2004
The function works properly when I test it. What is it doing that it shouldn't?
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 18
Reputation: hill0ster is an unknown quantity at this point 
Solved Threads: 0
hill0ster hill0ster is offline Offline
Newbie Poster

Narue ROCKS!!!

 
0
  #3
Oct 17th, 2004
Narue,
The problem is this. When you type in anything other than 's', 'h' or 'c', the program goes into the tryAgain function; as it should. And it you type in 'q' it quits the program. The problem is this, if you should be able to hit any other key a character or the enter key and it should output:
"Re-enter: 's' or 'S' for salaried, 'h' or 'H' for hourly, 'c' or 'C' for commissioned."
How do I get it to recognize the other keys and the enter key?
Any suggestions? Thanks, Paul.
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 5
Reputation: umair khan is an unknown quantity at this point 
Solved Threads: 1
umair khan umair khan is offline Offline
Newbie Poster

Re: Narue ROCKS!!! but need one last thing???

 
0
  #4
Oct 23rd, 2004
Originally Posted by hill0ster
Narue, thanks for all your help with this program! I really appreciate it. I have one last problem. In the function tryAgain, if user presses 'q' or 'Q'; the program terminates. No problem there, but if they hit anyother key; the program should allow them to re-enter pyrllSt (payroll status again). I don't believe I am getting into the second part of the if statement in the tryAgain function... Any suggestions? By the way the double suggestion works perfectly. You are one smart cookie. Thank you!

#include <iostream>
using namespace std;
#include <cstdlib>
#include <string>

bool getEmployeeData (int*, char*, double*, double*, double*, double);
float calculateGrossPay (char, double, double, double);
void displayEmployeeInfo(int, char, double);
bool tryAgain(char*);
bool isValidStatus(char*);

int main()
{
int ID = 0;
double Salary = 0;
double hourwrk = 0;
double sales = 0;
double grossPay = 0;
char pyrllSt = ' ';
float totalPayroll = 0.0;
bool result = true;
while (result)
{
result = getEmployeeData (&ID, &pyrllSt, &Salary, &hourwrk, &sales, totalPayroll);
if (result)
{
grossPay = calculateGrossPay(pyrllSt, Salary, hourwrk, sales);
totalPayroll += grossPay;
displayEmployeeInfo (ID, pyrllSt, grossPay);
}
else
{
cout << "Total Payroll for this month: " << endl;
cout << totalPayroll << endl;
}
}
return (1);
}

bool getEmployeeData (int *ID, char *pyrllSt, double *Salary, double *hourwrk, double *sales, double totalPayroll)
{
cout << "Enter employee ID: " << endl;
cin >> *ID;

if (*ID > 0)
{
cout << "Enter payroll status: " << endl;
cin >> *pyrllSt;
if (isValidStatus(pyrllSt))
{
if (*pyrllSt == 's' || *pyrllSt == 'S')
{
cout << "Enter monthly salary" << endl;
cin >> *Salary;
}

if (*pyrllSt == 'h' || *pyrllSt == 'H')
{
cout << "Enter number of hours worked this month: " << endl;
cin >> *hourwrk;
}

if (*pyrllSt == 'c' || *pyrllSt == 'C')
{
cout << "Enter total sales for this month: " << endl;
cin >> *sales;
}
}//if isValid Status
return true;
}
else
{
return false;
}
}

bool isValidStatus (char *pyrllSt)
{
bool isGood = true;

while (isGood)
{

isGood = (*pyrllSt == 's' || *pyrllSt == 'S' || *pyrllSt =='h' || *pyrllSt == 'H' || *pyrllSt == 'c' || *pyrllSt =='C');

if (isGood)
{
return true;
}
else
{
isGood = tryAgain(pyrllSt);
}
}
return false;
}

bool tryAgain(char *pyrllSt)
{
char quit;

cout << "Type Q or q to quit, any other key to continue: " << endl;
cin >> quit;

if (quit == 'q' || quit == 'Q')
{
cout << "*** Program Terminated ***" << endl;
return false;
}
else
{
cout << "Re-enter: 's' or 'S' for salaried, 'h' or 'H' for hourly, " << endl;
cout << "'c' or 'C' for commissioned." << endl;
cin >> *pyrllSt;
return true;
}
}

float calculateGrossPay (char pyrllSt, double Salary, double hourwrk, double sales)
{
float grossPay;
if (pyrllSt == 's' || pyrllSt == 'S')
{
grossPay = Salary;
}

if (pyrllSt == 'h' || pyrllSt == 'H')
{
grossPay = hourwrk * 18.75;
}

if (pyrllSt == 'c' || pyrllSt == 'C')
{
grossPay = sales * 0.06 + 1000.00;
}
return grossPay;

}

void displayEmployeeInfo (int ID, char pyrllSt, double grossPay)
{
cout << "Employee ID: " << ID << endl;
cout << "Payroll Status: " << pyrllSt << endl;
cout << "Gross Pay: " << grossPay << endl;
}

hi,
NAURE ROCKS:
I think your code is perfect.you should ask the user about the termination in the main body.
if any problem then send me the message.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC