Question

My C++ program is give me extra characters in my output. Below is an example of input.txt and the section of code that reads it. input.txt (x/y), x = 20, y = 5; ((y>x)&(x<z)),x=5,y=10,z=3; o...

My C++ program is give me extra characters in my output. Below is an example of input.txt and the section of code that reads it.

input.txt

(x/y), x = 20, y = 5;
((y>x)&(x<z)),x=5,y=10,z=3;

output I get:

Value=4 20, y=5;

Value=0z)), x=5, y=10, z=3;

ifstream fin;
        fin.open("input.txt");
    while (true)
    {
        symbolTable.init();
        fin.getline(line, SIZE);
        if (!fin)
            break;
        stringstream in(line, ios_base::in);
        in >> paren;
        cout << line << " ";
        expression = SubExpression::parse(in);
        in >> comma;
        parseAssignments(in);
        double result = expression->evaluate();
        cout << "Value = " << result << endl;
    }
    return 0;
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

try putting

while(getline(fin,line))

instead of while(true).

This would prevent duplicate values to be read from the file.

Add a comment
Know the answer?
Add Answer to:
My C++ program is give me extra characters in my output. Below is an example of input.txt and the section of code that reads it. input.txt (x/y), x = 20, y = 5; ((y>x)&(x<z)),x=5,y=10,z=3; o...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Please Update my C++ code: Implement array to replace for vector: Example --> input: 100 output:...

    Please Update my C++ code: Implement array to replace for vector: Example --> input: 100 output: A 1000Pairs.txt looks like this: {100, A } {200, A } {300, B } {400, C } {500, D } {600, E } {700, F } {800, G } {900, H } {1000, I } {1100, J } {1200, K } {1300, L } {1400, M } {1500, N } {1600, O } {1700, P } {1800, Q } {1900, R } {2000, S...

  • okay so here is my c++ code and the errors im really stuck on fixing what...

    okay so here is my c++ code and the errors im really stuck on fixing what i did wrong it seems to be the same repeated error our job is to write a menu driven program that can convert to display Morse Code ere is the menu the program should display Menu Alphabet Initials N-Numbers - Punctuations S = User Sentence Q- Quit Enter command the user chooses A your program should use a loop and your morse code printing...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT