Im writing a program that reads from a data file, does some math, and spits out some stuff to the console. It keeps reading the last line of the data file twice for some reason.
181239 13 I Y
091243 15.5 O N
872381 14 I N
992398 13.5 O Y
981237 10.5 I Y
987123 9 O N
738829 4.5 I N
873294 11.5 O Y
098372 17.5 I N
387923 16 O N
982347 5 O Y
473829 14 I N
983872 13 I N
908234 17 O Y
764828 19 O N
You should read the entire line with std::getline, then parse that line using istringstream.
You're not reading the last line twice, it's just that you haven't hit EOF until you attempt to read the next studentID. The read fails, but the variables all have the input from the last line, so you think it's read them again, it hasn't read anything.
Perhaps a much simpler way is not do it like this:
1 2 3 4 5
std::ifstream inData.open("Tuition.txt");
while (inData >> studentID >> hoursEnrolled >> residentialCode >> discountCode)
{
// process values
}