![]() |
| ||
| generate random question 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 ,,, |
| ||
| Re: generate random question Create an array of questions and use the random number as an index for the array. |
| ||
| Re: generate random question thank u... but i still don't know how to use array ...i know functions only ....if u can write some of the code ... |
| ||
| Re: generate random question >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; |
| ||
| Re: generate random 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; for(i=1;i<=2;i++) { if(r==0) printf("2*2=\na)4 b)2 c)3 d)5\n"); if(getchar()=='a'); counter++; else if(r==1) printf("2*5=\na)3 b)10 c)4 d)2\n"); if(getchar()=='b'); counter++; else if(r==2) printf("2*9=\na)3 b)10 c)18 d)2\n"); if(getchar()=='c'); counter++; } printf("your score is %d\n", counter); } |
| ||
| Re: generate random question 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. |
| ||
| Re: generate random question 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 ... |
| ||
| Re: generate random question #include <stdio.h> |
| ||
| Re: generate random question it runs .... :) thannnnnnk u very much and sorry for inconvenience.... |
| ||
| Re: generate random question >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. |
| All times are GMT -4. The time now is 11:35 am. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC