# Thread: Numbering questions that the user wants to answer.

1. ## Numbering questions that the user wants to answer.

Am learning really hard on this program, but am stuck. This code works fine for only one random equation, but now I need to get the user to ask the number of questions they need which will be given in number form, i.e question 1,2,3 and so on. I can't get that to work, also when they answer the question the score should be given at the end that is number correct. Any help will be appreciated. Thanks.
Code:
```//included libraries
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
#define  MAX_VAL 10

int main() {
//Variables declaration. This defines both the problem, random numbers and answer functions
int problem = 0, num1, num2, op, total;

//This function seeds the random function with the computer's internal clock
srand(time(0));

//To get random operator and random numbers -50 to 50 inclusive.
op = rand()%4;
problem =1 + rand ()%MAX_VAL;
num1 = (rand()%101)-50;
num2 = (rand()%101)-50;
total = rand()%10;

//Prints the welcome statement.
printf("Welcome! How many problems would you like?.\n\n");
scanf("%d", &problem);
printf("Here is random problem number:%\n", total);

//This part of the code generates the operation

while (op == problem){
answer = num1 + num2;
printf("%d + %d= ?\n", num1, num2);
}  if (op == 1) {
answer = num1 - num2;
printf("%d - %d= ?\n", num1, num2);
}  if (op == 2) {
answer = num1 * num2;
printf("%d * %d= ?\n", num1, num2);
}  if (op == 3) {
answer = num1 / num2;
printf("%d / %d= ?\n", num1, num2);

}

printf("\nCongratulations! You have answered the problem correctly!\n");

return 0;
}```

2. Your indentation, which is totally lacking, needs to improve real quick.
SourceForge.net: Indentation - cpwiki

3. What do you mean Salem?? Show me what indentation that is lacking and what I need to do; As explained earlier in each of my post, am still learning. And I need to know where I made the error so I can correct them. Thanks.

4. Currently, all of your lines of code start in column zero. Read the link Salem provided (click on the red text "SourceForge.net..."). Pay attention to how some lines are more indented than others. That helps you organize your code visually, so it's easier to understand when you read and write it.

5. This is your code, indented.
Code:
```//included libraries
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>

#define  MAX_VAL 10

int main()
{
//Variables declaration. This defines both the problem,
// random numbers and answer functions
int problem = 0, num1, num2, op, total;

//This function seeds the random function with the computer's internal clock
srand(time(0));

//To get random operator and random numbers -50 to 50 inclusive.
op = rand() % 4;
problem = 1 + rand() % MAX_VAL;
num1 = (rand() % 101) - 50;
num2 = (rand() % 101) - 50;
total = rand() % 10;

//Prints the welcome statement.
printf("Welcome! How many problems would you like?.\n\n");
scanf("%d", &problem);
printf("Here is random problem number:%\n", total);

//This part of the code generates the operation
while (op == problem) {
answer = num1 + num2;
printf("%d + %d= ?\n", num1, num2);
}
if (op == 1) {
answer = num1 - num2;
printf("%d - %d= ?\n", num1, num2);
}
if (op == 2) {
answer = num1 * num2;
printf("%d * %d= ?\n", num1, num2);
}
if (op == 3) {
answer = num1 / num2;
printf("%d / %d= ?\n", num1, num2);
}

printf("\nCongratulations! You have answered the problem correctly!\n");
return 0;
}```
Notice how it is so much easier to follow the program flow.

6. I am so sorry for not paying attention to indention. I will be more careful. Will someone please help.

7. Why are you assigning a random value to the "problem" variable, and then (without using this value) assigning user input to the same variable?

Code:
```problem = 1 + rand() % MAX_VAL;
// ...
scanf("%d", &problem);```
Also, if you enter the "while" loop, how do you expect to leave it? The values of "op" and "problem" never change in the body of the loop.

Code:
```while (op == problem)
{
answer = num1 + num2;
printf("%d + %d= ?\n", num1, num2);
}```
It appears that you need to re-think the "part of the code that generates the operation" - it doesn't appear to do what you think it does (unless I'm completely misunderstanding your goal here).

8. Well, I get the following when I compile, for starters:
Code:
```\$ make foo
gcc -Wall -g -std=c99  -lssl -lm -lpthread -lcurses -lefence  foo.c   -o foo
foo.c: In function ‘main’:
foo.c:29: warning: unknown conversion type character 0xa in format
foo.c:29: warning: too many arguments for format```
Which is this line:
Code:
`printf("Here is random problem number:%\n", total);`
I think you need a 'd' after the percent, like so: "...number: %d\n"

Then, you need to wrap all your logic for a single question/problem/equation in a loop, like so:
Code:
```ask user how many problems

for i from 0 to num_problems
get random operator, num1, num2
if operator == 1