Working on outputting either a real number or integer number
i’m reading in a number character by character from a file. It will read an integer and push it into integerQueue up until it reaches a ‘.’, then it will switch to inputting it into a realQueue.
Then when i print, it needs to print out i.e. Real: 123.4343
But right now the output is Real: 123. Integer 4343
Somehow my while loop or my if statement isn’t doing its job. I just can’t find my error
question is, How do I fix my output so that it prints out 123.4343
//if the realQueue is empty, then we just read in an integer, currentState must be 1, in order to print integer
if(realQueue.empty() || currentState == '1')//implementation of the FSM
{
writeFile <<"Integer: ";
while(!integerQueue.empty())
{
writeFile <<integerQueue.front();
integerQueue.pop();
}
}
//since the realQueue has values in it, then it must bea real Number
else
{
//currentState = '2';
// currentState must be == '2', since wwe have a real number to print
writeFile<<"Real: ";
//currentState has to be in real mode for it to print out to file
while(!integerQueue.empty() && currentState == '2')
{
writeFile <<integerQueue.front();
integerQueue.pop();
}
// currentState has to be in real mode for it to print out to file
while(!realQueue.empty() && currentState == '2')
{
writeFile <<realQueue.front();
realQueue.pop();
}
}
Try comminting this loop out and see what happens.