Link to home
Start Free TrialLog in
Avatar of bananaamy
bananaamy

asked on

Break statement question.

I have a break statement that I have wrote (see below) What would the correct synyax(if it is possible) to add one more statement that is a catch all for all other entries. - I tried adding a while/do statement but that idea doesnt seem to work. Should I be including this in the switch statement or before? The while staement that I attemped is posted below too. Please advise. (Prefer comments and suggestions as opposed to writting the code for me., ) And as always, Thxs much!!

float Wages::assignHourlyRate()
{
      cout << "Enter classification: ";
      cin  >> classification;
      classification = toupper(classification);  ///I put the while statement here///
         switch (classification)
      {      
      case 'A':rate = 10.25;break;
      case 'B':rate = 8.5;break;
      case 'C':rate = 6.3;break;
      case 'D':rate = 4.65;break;
      }
      system ("Pause");
      return 0;
}
while
      (classification != 'A'||classification != 'B'||classification != 'C'||classification != 'D')
            do
      cin  >> classification;                        
Avatar of jkr
jkr
Flag of Germany image

You'd add a 'default:' statement, e.g.

float Wages::assignHourlyRate()
{
    bool bClassificationOK= false;
    cout << "Enter classification: ";

    while ( !bClassificationOK) {
    cin  >> classification;
    classification = toupper(classification);
    bClassificationOK = true; //assume the best
       switch (classification)
    {    
     case 'A':rate = 10.25;break;
    case 'B':rate = 8.5;break;
    case 'C':rate = 6.3;break;
    case 'D':rate = 4.65;break;
    default:  bClassificationOK = false; break; // reset if unknown
    }
    } // end while
    system ("Pause");
    return 0;
}
ASKER CERTIFIED SOLUTION
Avatar of rghome
rghome

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Um, and what about the 'break;' statement thing?