Who can help?This is Urgent

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • reshmidoudou
    New Member
    • Oct 2006
    • 9

    Who can help?This is Urgent

    i am doing a program where I have to input an equation and from there , there must be only 5 inputs from the keyboard if more than 5 inputs are done the pgm must display an error message. The program is as follows:

    int var1, var2, result;
    string eq, op;

    cout << "Type the equation : ";
    cin >> var1 >> op >> var2 >> eq >> result;

    example if the user types the equation :
    2 + 3 = 5 (5inputs)
    but

    2 + 3 = 0 + 5 ( invalid bcos more than 5 inputs r done)

    how do I do the validation?
  • zahidkhan
    New Member
    • Sep 2006
    • 22

    #2
    Originally posted by reshmidoudou
    i am doing a program where I have to input an equation and from there , there must be only 5 inputs from the keyboard if more than 5 inputs are done the pgm must display an error message. The program is as follows:

    int var1, var2, result;
    string eq, op;

    cout << "Type the equation : ";
    cin >> var1 >> op >> var2 >> eq >> result;

    example if the user types the equation :
    2 + 3 = 5 (5inputs)
    but

    2 + 3 = 0 + 5 ( invalid bcos more than 5 inputs r done)

    how do I do the validation?

    Use command line arguments instead of reading it from console
    or take an input as string expression using cin.getline and later parse the string to operands and operator.

    Comment

    Working...