# Help! Calculator Not Working...What is wrong?

• 08-07-2013
Help! Calculator Not Working...What is wrong?
Nothing wrong with compling, all done, but the EXE will not work when I calculate it.
Some One Know What is going on?
Code:

```int main () {     cout << "welcome to My First Calc!";     cout << "Enter The ID Of the Task.\n 1.Add\n2.Subtract\n3.Multiply\n4 Divide\n";     int taskid;     cin >> taskid; // taskid is the Task ID.     cout << "Enter the first number.\n";     int num1;// the First Number     cin >> num1;     cout << "Now the Second.\n";     int num2;// the second number     cin >> num2;     int result; // defining the result variable earlier     if (taskid == 1)     {         cout << "Results:";         result = num1 + num2;         cout << result;         cout << "Bye!";         cin.get();     }     else if (taskid == 2)     {         cout << "Results:";         result = num1 - num2;         cout << result;         cout << "Bye!";         cin.get();     }     else if (taskid == 3)     {         cout << "Results:";         result = num1 * num2;         cout << result;         cout << "Bye!";         cin.get();     }     else if (taskid == 4)     {         cout << "Results:";         result = num1 / num2;         cout << result;         cout << "Bye!";         cin.get();     }     else     {         cout << "Error:UNknown Task ID";         cout << "Bye!";         cin.get();     } }```
Testing Enviroment:
Windows 7 64Bit
IDE:
Dev-C++ 7.4.2 (Portable)
• 08-08-2013
Salem
Seems OK to me.
Code:

```\$ g++ foo.cpp \$ ./a.out welcome to My First Calc!Enter The ID Of the Task.  1.Add 2.Subtract 3.Multiply 4 Divide 1 Enter the first number. 12 Now the Second. 22 Results:34Bye!```
Perhaps the screen disappears as soon as you enter the last number....

Your cin.get() only consumes the newline after the input of the 2nd number, it does not wait for you to press a key.
• 08-08-2013
How do I Solve this issue?
• 08-08-2013
vart
Run it from command line
or
Run it with Ctrl+F5 (if in VS)
or
read FAQ > Flush the input buffer - Cprogramming.com
or use
cin.ignore http://www.cplusplus.com/reference/i...stream/ignore/
• 08-08-2013
Quote:

Originally Posted by vart
Run it from command line
or
Run it with Ctrl+F5 (if in VS)
or
read FAQ > Flush the input buffer - Cprogramming.com
or use
cin.ignore istream::ignore - C++ Reference

How do I use cin.ignore? I use Dev-C++ not VS and can you modify my code to let it work? I am a noob!
• 08-08-2013
Elysia
cin.ignore is standard C++, so it will work everywhere, regardless of your IDE.
Simply put
std::cin.ignore(std::numeric_limits<std::streamsiz e>::max());
Before a std::cin.get() to ignore everything in the input buffer.
EDIT: Remove space between "std::streamsiz" and "e". Board is incorrectly placing it there for some reason.
• 08-08-2013