Hi im very new to C programming and I was writing a program to generate two random numbers who's answer the user has to guess, and the program will tell if the answer is right or wrong. While I have managed to do that, I have no clue how to produce a list of 10 random multiplication questions the user has to guess. Here is the code so far:
I know to generate a list I have use loops and arrays but I'm completely clueless about it.Code:#include <stdio.h> #include <stdlib.h> #include <time.h> int main(void) { int n1, n2; long prd, guess; srand((unsigned int)time(NULL)); n1 = 1 + (int)(100.0 * (rand() / (RAND_MAX + 1.0))); n2 = 1 + (int)(100.0 * (rand() / (RAND_MAX + 1.0))); prd = n1 * n2; printf("What is the product of %d and %d\?\n" "[Enter -1 to exit]\n", n1, n2); if(scanf("%ld", &guess) != 1) { puts("Incorrect input."); return EXIT_FAILURE; } else if(guess == -1) { puts("bye."); } else if(guess == prd) { puts("Correct!"); } else { puts("Wrong guess."); } return 0; }



LinkBack URL
About LinkBacks


