Purchase Solution

c++ cin.ignore function

Not what you're looking for?

Ask Custom Question

I wrote the following c++ code to a source file

/this program will calculate federal and fica taxes withheld and calculate net pay
//for an employee

#include <iostream>
#include <string>
#include <stdlib.h>
using namespace std;

//function prototypes

void empInput(string&, float&, float&, float&);
float calcFwt(float, float);
float calcFica (float, float);
float calcNetPay (float, float, float);
void dispEPay (string, float, float, float);

int main ()
string name = "";
float wkSal = 0.0;
float fedWld = 0.0;
float fedWldRate = 0.0;
float ficaWld = 0.0;
float ficaWldRate = 0.0;
float netPay = 0.0;
int howMany = 0;
int count;

cout<<"Please enter the number of employees you want to process: ";
cin>> howMany;

//begin loop

for (count = 1; count <= howMany; count++)
//enter input items

empInput(name, wkSal, fedWldRate, ficaWldRate);

//calculate fed tax

fedWld = calcFwt(wkSal, fedWldRate);

//calculate fica tax

ficaWld = calcFica(wkSal, ficaWldRate);

//calculate net pay

netPay = calcNetPay(wkSal, fedWld, ficaWld);

//display employees name pay and taxes withheld

dispEPay(name, fedWld, ficaWld, netPay);

return 0;
}//end of main function

//*********program defined function**********

void empInput(string& emp, float& salary1, float& tax1, float& tax2)

cout<<"Please enter employee's name: ";
getline(cin, emp);
cout<<"Please enter employee's salay: ";
cin>> salary1;
while(salary1 < 0)
cout<<"Salary should be a positive number: ";
cout<<"Please enter employee's salary: ";
cin>> salary1;
cout<<"Please enter federal income tax rate: ";
cin>> tax1;
while(tax1 < 0)
cout<<"The tax rate should be a positive number: ";
cout<<"Please enter federal income tax rate: ";
cin>> tax1;
cout<<"Please enter the fica tax rate: ";
cin>> tax2;
while(tax2 < 0)
cout<<"The tax rate should be a positive number: ";
cout<<"Please enter the fica tax rate: ";
cin>> tax2;
cin.ignore (1);
}//end of getinput function

float calcFwt(float empsal, float fedrate)
return empsal * fedrate;

}//end of calcfwt function

float calcFica(float salary, float ficarate)

return salary * ficarate;

}//end of calcFica

float calcNetPay(float esalary, float fed, float fica)

return esalary - fed - fica;

}//end of netpay function

void dispEPay(string employee, float fed1, float fica1, float pay)
cout<<"Employee's name: "<< employee << endl;
cout<<"Federal tax withheld: "<< fed1 << endl;
cout<<"FICA tax withheld: "<< fica1 << endl;
cout<<"Employee's net pay is $: "<< pay << endl;

system ("pause");
system ("cls");
}//end of dispepay function

My problem is when I run it, after I enter the employee's name, I have to push enter twice before it will say enter salary. I think I am doing something wrong w/cin.ignore

(My program really is not out of line like it shows here it just did that when i cut and pasted it)

Purchase this Solution

Solution Summary

This job features c++ cin.ignore function. The federal and fica taxes withheld are calculated.

Solution provided by:
  • BEng, Allahabad University, India
  • MSc , Pune University, India
  • PhD (IP), Pune University, India
Recent Feedback
  • " In question 2, you incorrectly add in the $3.00 dividend that was just paid to determine the value of the stock price using the dividend discount model. In question 4 response, it should have also been recognized that dividend discount models are not useful if any of the parameters used in the model are inaccurate. "
  • "feedback: fail to recognize the operating cash flow will not begin until the end of year 3."
  • "Answer was correct"
  • "Great thanks"
  • "Perfect solution..thank you"
Purchase this Solution

Free BrainMass Quizzes
Word 2010: Tables

Have you never worked with Tables in Word 2010? Maybe it has been a while since you have used a Table in Word and you need to brush up on your skills. Several keywords and popular options are discussed as you go through this quiz.

Basic Networking Questions

This quiz consists of some basic networking questions.

Basic UNIX commands

Use this quiz to check your knowledge of a few common UNIX commands. The quiz covers some of the most essential UNIX commands and their basic usage. If you can pass this quiz then you are clearly on your way to becoming an effective UNIX command line user.

Javscript Basics

Quiz on basics of javascript programming language.

C++ Operators

This quiz tests a student's knowledge about C++ operators.