hi all...i am a not that much in programming ...

i would ask you how i can generate a multiple choice question chosen randomly from a list of questions with answers using functions in C program ...i know how to generate random numbers only ...

help me please ,,, as soon ,,,

Create an array of questions and use the random number as an index for the array.

thank u...

but i still don't know how to use array ...i know functions only ....if u can write some of the code ...

>but i still don't know how to use array
So use a series of if statements, do you know how to use those? :rolleyes:

int r = rand() % N;

if ( r == 0 )
  /* First question */
else if ( r == 1 )
  /* Second question */
else if ( r == N - 1 )
  /* Nth question */

i try these code that i want 2 questions appear randomly from 3 quetions ..but still don't work.. :sad: :sad:

#include <stdio.h>
#include <stdlib.h>

int main()
    int N,counter,i;
    int r = rand() % N;

    printf("2*2=\na)4  b)2  c)3  d)5\n");

    else if(r==1)
    printf("2*5=\na)3  b)10  c)4   d)2\n");

    else if(r==2)
    printf("2*9=\na)3  b)10  c)18   d)2\n");

printf("your score is %d\n", counter);

commented: Use code tags. +0

Call rand every time you want a random number. If you only get one random number then you'll always have the same question. You would think this would be obvious. I guess I just expect too much from other people.

I still can't solve it >>>

thank u ...and if u can give more help ...i'd be happy ..i try it ...but i can't generate random questions ....

thank u ...

#include <stdio.h>
#include <stdlib.h>

int main()
  int N = 3,counter,i;

    int r = rand() % N;

    if(r==0) {
      printf("2*2=\na)4 b)2 c)3 d)5\n");
    else if(r==1) {
      printf("2*5=\na)3 b)10 c)4 d)2\n");
    else if(r==2) {
      printf("2*9=\na)3 b)10 c)18 d)2\n");
  printf("your score is %d\n", counter);

  return 0;

it runs .... :)

thannnnnnk u very much

and sorry for inconvenience....

>and sorry for inconvenience....
No, it's my fault. I didn't look closely enough at the code to see all of your problems. If I had things would have gone much more quickly, and for that I appologize.

I have 100 Rs. I want to earn interest by lending money to other people. I can lend
the money for 10 days with 20% interest rate per month or 20 days with 10%
interest rate per month. Write a program to calculate interest for both cases &
choose the best option to earn more money.in c

Hi good day, I need your help :)
this is a C language

"Write a program that accepts an input computed by a constant (10)
Sequence of output:
output sum twice (increment by 1)
Output product twice (decrement by 1)
Output average twice (increment by 2)"

commented: You need to create a new discussion and show your work. Burying your question under 15 years of discussion is hiding it. -4
Be a part of the DaniWeb community

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