Do While loop - identifier not declared

advertisements

Good day guys, I want to ask why my variable was undeclared although i declared it at first. my typeSel variable in the while loop does have an underline which was found undeclared identifier. Thanks for helping

int quantity, typeSel; // quantity, modify type
double weight;
string w,q; // weight, quantity
char modSel; // modify selection

if( modSel =='y'|| modSel == 'Y'){

    do{
        cout << "What do you want to change : " << endl;
        cout << "1. Flavour" << endl << "2. Weight" << endl << "3. Quantity" << endl;
        cin >> typeSel;
    }while(typSel != 1 && typSel != 1 && typSel != 1);

    if(typeSel == 1){
        Flavour();
    }
    else if(typeSel == 2){

    }
    else if(typeSel == 3){

    }
}


typSel and typeSel are not the same identifier.

Let's have a look at them in close proximity, maybe it will be clearer:

typSel
typeSel
   ^
   |
   +-- here

:-)

In addition, while I appreciate some people may not totally trust computers, asking then to verify a variable isn't a specific value shouldn't need to be done three times. You may want to check for a couple of other values than just 1.

Change:

}while(typSel != 1 && typSel != 1 && typSel != 1);

into:

} while (typeSel != 1 && typeSel != 2 && typeSel != 3);

and you should be fine.