Im using getline into a string and pushing back into a vector. The output is missing the first two characters though. How do you get it to display all of the input??
#include <iostream> //
#include <string>
#include <vector>
#include <iomanip> //Identify libraties (delcarations)
#include <math.h>
#include <algorithm>
#include <conio.h>
usingnamespace std;
int main ()
{
vector<string> Names;
vector<double>Hours; //initializes vectors
vector<double>Payrate;
vector<char>Union;
vector<double>Uniondues;
vector<double>Gross;
vector<double>Overtime;
vector<double>Tax;
vector<double>Net;
vector<double>RegPay;
double dues;
char code;
double hrs; //intializes strings, chars and doubles
double grade;
string EmID;
double regpay;
double overtimepay;
double grosspay;
double fedtax;
double netpay;
cout<<"\t\t\t Earning statement Mod. Please have all nessesary information on hand\n";
for (int i= 0;i<1;i++) // starts loop tp input and validate information into vectors
{ cout<< " Please Enter the Employee's Identifer.\t";
cin.ignore(); // used ignore to reset after using getline
cin.get(); //cin.get is used to complete reset to successfully use both getline and cin
getline( cin, EmID); // stores data from(cin) line including whitspaces usesul if we wanted to identify employ w/ full name (stores in EmID)
Names.push_back(EmID); // adds (expands) the vector Names by one as data is placed into vector as EmID.
cout<< "Hours worked?";
cin>>hrs;
while (hrs<0 || hrs>=60) // while loop for hours worked verification (conditions line)
{(cout<< "Hours exceed Maxium Allowable work Hours. \n"); // while loop command line for invalid conditions
cout<< "\n";
cout<< "\n";
cout<< "\n\t\t\t.. Enter Hours worked."; // command user to add input
cin>>hrs;} // input
Hours.push_back(hrs); // adds (expands) the vector Hours by one as data is placed into vector as hrs.
cout<< " Enter employee payrate.\t"; // command user to add input
cin >> grade; // input
while(grade<7.50 || grade>45.00) // while loop conditions
{
(cout<< "Payrate not withing Allowable Range.");
cout<< "\n";
cout<< "\n";
cout<< "\n\t\t\t.. Enter Valid Payrate.";
cin>>grade;}
Payrate.push_back(grade); // adds (expands) the vector Payrate by one as data is placed into vector as grade.
cout<< "what is code?";
cin>> code;
while(code!='A' &&
code!='a' && // while loop to define nessesary conditions
code!='B' &&
code!='b' &&
code!='C' &&
code!='c')
{
cout<<" Inputted union code is invalid.\n"; // if conditions invalid output cout<<
cout<<" Enter valid Union Code\n";
cin>>code; // then ask and cin>> correct input
}
switch (code) //switch statement to assign dues to the accepted Union code
{
case'A': case'a':
dues= 25.00;
break; //breaks allow the next case to be ran if prev case fail
case'B' : case'b':
dues= 50.00;
break;
case'C' : case'c':
dues= 75.00;
break;
default:break; // uses break as a default since values were checked in while loop
}
Union.push_back(code); // adds (expands) the vector Union by one as data is placed into code.
Uniondues.push_back(dues); // adds (expands) the vector Uniondues by one as data is placed into dues.
// if statements checks the truth of data and set rules to govern program based if data is true
if
// if true hoursworked is less or equal to 40
(hrs <= 40)
// regpay will equal the number of hours worked times the payrate
{
regpay = (hrs * grade);
overtimepay=0;
}
// if true hoursworked is greater than 40
if (hrs > 40)
// regpay is (40) times pay rate
{
regpay = ((40)* grade);
overtimepay = (1.5*(hrs-40)* grade);
}
//gross pay = regualar pay plus any overtime pay.
grosspay = ( regpay + overtimepay);
//if gross pay is greater than 2000
if (grosspay > 2000)
// federal tax rate is 25% of the gross pay
{
fedtax = (0.25*grosspay);
}
//if gross pay is more than $1000 and lss than or equal to $2000
if (grosspay > 1000 && grosspay<= 2000)
// then federal tax rate is 15% of the gross pay
{
fedtax =( 0.15*grosspay);
}
// declares alternative for all other values not listed
else
// then federal tax rate is 10% of the gross pay
{
fedtax = (0.10 * grosspay);
}
netpay = (grosspay - (fedtax + dues));
Gross.push_back(grosspay);
Overtime.push_back(overtimepay);
Tax.push_back(fedtax); // Adds all of the calculated values to the appropriate vectors
Net.push_back(netpay);
RegPay.push_back(regpay);
}
// print names
for (int i= 0; i<1; i++)
{
//fixed sets the output to decimal instead of scientific notaion and // Caluates results are formatted to two decimal places by setprecision(2).
cout<<fixed<<setprecision(2);
cout<<"\n Earning Statement for Employee: "<<Names[i]<<endl;
cout<<"\t\t\t Total Hours worked this pay period: "<<Hours[i]<<endl;
cout<<"\t\t\t Dedcuted Uniondues this pay period: "<<Uniondues[i]<<endl;
cout<<"\t\t\t Gross: "<<setw(35)<<Gross[i]<<endl;
cout<<"\t\t\t Total Base Pay is: "<<setw(23)<<RegPay[i]<<endl;
cout<<"\t\t\t Overtime Pay is: "<<setw(23)<<Overtime[i]<<endl; // outputs infomation from vectors
cout<<"\t\t\t Net Pay is: "<<setw(29)<<Net[i]<<endl;
cout<<"\t\t\t Federal Tax Amount Deducted: "<<setw(12)<< Tax[i]<<endl;
}
// Caluated results are formatted to two decimal places by setprecision(2).
// The output statement to display an appropriate end-of-program message.
cout<< "\t\t\t This program is for training purposes only.\n \t\t\t\t Have a nice day...";
system ("pause");
return 0;
}
I know because I tried to remove them but by removing them both causes a problem. they are problematic in themselves as I use them due to them making the output go beserck if I enter an invalid value. Instead of simply outputing " enter valid entry" prints a ton of invalids and enter valid phrases. Removing them wont allow me to capture whitespaces. What should I do?