getline not returning all of my data

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??
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
  #include <iostream> //

#include <string>

#include <vector>

#include <iomanip> //Identify libraties (delcarations)

#include <math.h>

#include <algorithm>

#include <conio.h>

using namespace 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;
}
Let's see.. you're missing two characters when you use getline, but every getline is preceded by:

cin.ignore();
cin.get();


which behaves exactly like two consecutive ignores. In other words, they each discard input. Stop discarding input you don't want to discard.
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?
The problem you're encountering is probably due to a newline left in the input stream after formatted extraction.

If that is the case, try changing:

1
2
3
cin.ignore();
cin.get();
getline(EmID, cin);


to:

1
2
cin >> ws ;   // removes any whitespace before the next token.
getline(EmID, cin);

Topic archived. No new replies allowed.