samedi 7 août 2021

I want to run a YES/NO loop to enter a list of students using vector

Here's My code and I can't get what am I doing wrong in this. It's not working continuously for input string after every pressed 'y' or 'Y'. Instead, it is displaying the Question message again and again after first string input. CAN YOU HELP ME TO RESOLVE THIS.

int main(){
    vector<string> v;
    int count=0;
    bool value=true;
    string s;
    char ch;
    cout<<"Start entering the name of the students :- "<<endl;
    while(value){
        getline(cin,s);
        v.push_back(s);
        count++;
        cout<<"Do you want to Enter one more name :- Press 'y/Y' to continue or 'n/N' to end -> ";
        cin>>ch;
        if(ch=='n'||ch=='N') value=false;
    }
    cout<<"So, there are total "<<count<<" number of students and their names are :-"<<endl;
    for(auto x:v) cout<<x<<endl;
    return 0;
}

Aucun commentaire:

Enregistrer un commentaire