Don't use gotos. Never, ever, *ever* use gotos. (Unless you can demonstrate decisively that they simplify program logic over the alternatives. Which you almost never can really do.)
The correct way to write this would be:
Code:do { { cout<<" SC J 1.0 (BETA) " <<endl; cout<<endl; cout<<"( simple calc J )"<<endl; cout<< endl; } // Enter the first value cout<<"First Number: "; cin>> a1; cout<<endl; cout<<"Press: + to add, - to subtract, * to multiply and / to divide and press enter "; cin >> a; cout<<endl; //if user inputs + then add if ( a == '+' ) { stuff here } else if ( a == '-' ) { //stuff here } else if ( a == '*' ) { // stuff here } else if ( a == '/' ) { // stuff here } } while (1); // or whatever condition you want to terminate the loop, maybe a particular character.This is incorrect use of the comma operator. It does not do what you think it does. In general the correct way to write this (unnecessary in the above example, BTW) would be:Code:if (a != '+', '-', '*', '/' )
Although, in the particular case where you're trying to match one of several chars you could instead just writeCode:if (a != '+' && a != '-' && a != '*' && a != '/')
Code:if (strchr("+-*/",a) == NULL)




Reply With Quote