user3661531 user3661531 - 1 year ago 220
C Question

Variable warning set but not used

int none[5];
int ntwo[5];

(the following is in a switch statement);

if (answer == userAnswer)
score = prevScore + 1;
prevScore = score;

printf("Incorrect. The correct answer was %d\n\n", answer);
none[i] = number1;
ntwo[i] = number2;

(Switch statement ends)

It gives me an error saying "Variable warning "none" set but not used". I have clearly used it. I dont know why this error i happening. FYI all the other variables you see have been declared. I just took out the imp part where the array appears.

Answer Source

none shows up twice in this code snippet:

int none[5]; // declared, not set to anything

And then:

none[i] = number1; // a value has been set, but it's not being used for anything

If, for example, you later had:

int foo = none[3];  // <-- the value in none[3] is being used to set foo


for(int i = 0; i < 5; i++)
    printf("%d\n", none[i]);   // <-- the values in none are being used by printf

or something to that effect, we would say none is "used", but as the code is, you have: "none" set but not used; exactly what the compiler said.

In the pastebin link I see your problem:

You wrote this:

    printf("Question [i]: none[i]+ntwo[i]");

You meant to write this:

    printf("Question [i]: ", none[i]+ntwo[i]);

Now none is being used and your print is doing something useful...

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download