[Really simple problem] Loop condition not working?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
int cont1=0;
    char agenda[100][30][3] = {{{999}}};
    int contprincipal=10;
    char nome[30];
    cout << "Seja bem vindo!" << endl;
    while (contprincipal!=0) {
    cout << "-----MENU------" << endl;
    cout << "1. Inserir novo contato" << endl;
    cout << "2. Buscar contato" << endl;
    cout << "3. Excluir contato" << endl;
    cout << "0. Encerra o programa" << endl;
    cin >> contprincipal;
    cin.clear();
    cin.ignore(10000,'\n');
    if (contprincipal==1&&agenda[cont1][0][0]==999) {


Self explanatory. Even when i press "1" in the first "CIN", the program wont enter the first loop.
What does the rest of your code look like? Not sure why you are using cin.clear() and cin.ignore() right after the input.

Not really sure on the problem getting into the if statement, but then I've never dealt with a 3-d array either. I'm pretty sure that you can initialize 2-d and 3-d arrays to a value with simply one set of braces like this: char agenda[100][30][3] = {999} but don't quote me on that.

Actually, now that I think about it that would prolly only initialize the first element and set the rest to 0. I don't know if that's what you were looking to do or not. I don't know if there is any way, outside of a nested for series, to set an entire array to the same value.
Last edited on
Topic archived. No new replies allowed.