darkangel29 |
10-08-2008 08:21 PM |
cin and do while problems
This a code for a calculator I'm doing.
main.cpp
Code:
#include <string>
#include "Equation.h"
using namespace std;
int main()
{
Equation a;
string expresion;
char option;
do{
cout<<"\tMathematic Expression Calculator" << endl;
cout<<endl;;
cout<<"\ta) Enter Expression" << endl;
cout<<"\tb) Help" << endl;
cout<<"\n\tc) EXIT" << endl;
cout<<endl;
cout<<"\tOption: ";
cin>>option;
switch(option)
{
case 'a':
system("cls");
cout<<"Enter the expression: ";
getline(cin,expresion);
a.set(expresion);
a.rpn();
system("pause");
system("cls");
break;
case 'b':
system("cls");
cout<<"This calculator calculates the result of an mathematic expression.";
cout<<"\nIt uses the methodology of postfix to help calculate this.";
cout<<"\nExample mathematic expression is 4+5*(7-5)"<<endl;
system("pause");
system("cls");
break;
case 'c':
system("cls");
cout<<"Have a nice day."<<endl;
break;
default:
system("cls");
cout<<"\n\tInvalid Option\n"<<endl;
break;
}
}while(option !='c');
return 0;
}
The code works fine but the problem is that when i try to implement the do while loop as you can see and the user chooses a to enter a expression it just skips the getline completely. If I don't do the do while loop everything works great. What I'm doing wrong here? Thanks
I didn't include the Equation.cpp file because is a little to long and I know is working but if you needed let me know. Also I have tested this in MS Visual 2005 and MS Visual 2008.
|