lundi 21 décembre 2020

How To Fix Unexpected Loop In C++

I'm making a simple data management system which have 3 services

  1. Add a student.

  2. View a student information.

  3. Delete a student

The code looks like this :

#include <iostream>
using namespace std;
enum Services
{
    Add=1,
    View,
    Del
};
class Student
{
public:
    string Name;
    int Age;
    string Gender;
    int Class;
    
    Student(string Name,string Gender,int Age,int Class)
    {
        this->Name=Name;
        this->Gender=Gender;
        this->Age=Age;
        this->Class=Class;
    }
};
int main()
{
    //Bio Variables
    string Name;
    string Gender;
    int Age;
    int Class;
    
    std::cout<<"•Add A Student [PRESS 1]\n•View Student's Information [PRESS 2]\n•Delete A Student [PRESS 3]"<<endl;
    //Creating Instance Of Service ENUM
    Services Serv;
    do
    {
        cout<<"\nWhich Service Do You Want To Access :";
        int Service;
        cin>>Service;
        Service=0;
    }while(Serv!=Add || Serv!=View || Serv!=Del || !cin);
}

It works fine but when I give a input in string it keeps on looping without giving me a chance to give an input again.

Before giving input as string

After giving input in string

Please help me fix this weird error.

PS:- The code isn't complete yet.

Sorry for bad English.

Aucun commentaire:

Enregistrer un commentaire