lundi 17 décembre 2018

Can't get it back to loop. C++

I'm trying to get it back to loop if they enter anything from the choices. everytime I enter 4, it just ends. and if I pick the right one it also ends. Is there anyway I can get it to ask user to input the right one?

void towsoncourse ()
{
cout << "Enter Course: 1 is COSC,2 is ENGL,3 is MATH" << endl;
int course;
bool finish;

bool finishcourse = true;
cin >> course;

while (finishcourse != true)
{
    cout << "Enter correct number for course" << endl;
        if (course == 1 || course == 2 | course == 3)
    {
        finish = true;
    }
        else
    {
        cout<< "Error: Enter number corresponding to course." << endl;
    }
 }

     switch (course)
     {
        case 1:
        cout << "COSC" << endl;
        break;
        case 2:
        cout << "ENGL" << endl;
         break;
        case 3:
        cout << "MATH" << endl;
         break;
        default:
        cout << "Error: Enter number corresponding to course" << endl;
}
}

int main ()
{
  towsoncourse ();

  return 0;
}

Aucun commentaire:

Enregistrer un commentaire