the loop runs infinte for the second ittiration

//attempt two to make the student data base the other way
// this program  runs onlu once and does not hav any data base once u exit


using std::cout;
using std::endl;
using std::cin;

int count=0;
class student
    double m_roll[100],m_class[100];
    char m_name[100],m_adress[100];
    void getdata(int count)
    cout<<" enter the name"<<endl;
    void read_data(int count)
        if (count==0)
            cout<<"no data found";

        for (int i=0;i<count;i++)


int main()
    int user_input=0;

    student student1;
    cout<<"enter a choice"<<endl;
    cin>> user_input;


    }while (user_input!=4);


Recommended Answers

The only loops you've got seem to work fine, even after several iterations.

Jump to Post

All 4 Replies

The only loops you've got seem to work fine, even after several iterations.

What exactly is your question?

it works gud only at first itiration.. tat is the do-while loop.. after the first run.. it askes me to enter a choice a infinite times

Yes, indeed.
Line 20:


should be


Also, it is ill-advised to use the #include <conio.h> header, because is a non-standard include, and is OS dependent (mainly Windows).

You printing function is also wrong.
For example, if I type in option 1, and I put there some string, for example, lol, the count (which would be 0 at first) would be incremented by 1. When calling the printing function, it will print only the first letter from that string, meaning l, because the for goes from 0 to count (which will be 1). I do suggest using strings: Click Here, both for values and for validating the loop entries.
Speaking of loops, your loop is not retard-proof. If I insert for example the character 's' in the option menu, instead of 1, 2 or 4, what would it happen? Do a simple for-based validation over a string in order to get your loop nicely done:

std::string answer; //#include <string>
for (;;){
    cout<<"Insert option: ";
    if (answer == "4") break;
    else if (answer == "1") //do option 1
    else if (answer == "2") //do option 2
    //... conditions
    else cout<<"Invalid command.\n";
Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.