generate random question

Reply

Join Date: Nov 2004
Posts: 5
Reputation: ams is an unknown quantity at this point 
Solved Threads: 0
ams ams is offline Offline
Newbie Poster

generate random question

 
0
  #1
Nov 8th, 2004
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 ,,,
Last edited by ams; Nov 8th, 2004 at 6:48 am. Reason: to complete HW
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,566
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 705
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: generate random question

 
0
  #2
Nov 8th, 2004
Create an array of questions and use the random number as an index for the array.
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 5
Reputation: ams is an unknown quantity at this point 
Solved Threads: 0
ams ams is offline Offline
Newbie Poster

Re: generate random question

 
0
  #3
Nov 8th, 2004
thank u...

but i still don't know how to use array ...i know functions only ....if u can write some of the code ...
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,566
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 705
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: generate random question

 
0
  #4
Nov 8th, 2004
>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:
  1. int r = rand() % N;
  2.  
  3. if ( r == 0 )
  4. /* First question */
  5. else if ( r == 1 )
  6. /* Second question */
  7. ...
  8. else if ( r == N - 1 )
  9. /* Nth question */
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 5
Reputation: ams is an unknown quantity at this point 
Solved Threads: 0
ams ams is offline Offline
Newbie Poster

Re: generate random question

 
-1
  #5
Nov 9th, 2004
i try these code that i want 2 questions appear randomly from 3 quetions ..but still don't work..

#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);

}
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,566
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 705
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: generate random question

 
0
  #6
Nov 9th, 2004
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'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 5
Reputation: ams is an unknown quantity at this point 
Solved Threads: 0
ams ams is offline Offline
Newbie Poster

Re: generate random question

 
0
  #7
Nov 10th, 2004
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 ...
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,566
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 705
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: generate random question

 
0
  #8
Nov 10th, 2004
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int main()
  5. {
  6. int N = 3,counter,i;
  7.  
  8. for(i=0;i<10;i++)
  9. {
  10. int r = rand() % N;
  11.  
  12. if(r==0) {
  13. printf("2*2=\na)4 b)2 c)3 d)5\n");
  14. if(getchar()=='a')
  15. counter++;
  16. }
  17. else if(r==1) {
  18. printf("2*5=\na)3 b)10 c)4 d)2\n");
  19. if(getchar()=='b')
  20. counter++;
  21. }
  22. else if(r==2) {
  23. printf("2*9=\na)3 b)10 c)18 d)2\n");
  24. if(getchar()=='c')
  25. counter++;
  26. }
  27. getchar();
  28. }
  29. printf("your score is %d\n", counter);
  30.  
  31. return 0;
  32. }
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 5
Reputation: ams is an unknown quantity at this point 
Solved Threads: 0
ams ams is offline Offline
Newbie Poster

Re: generate random question

 
0
  #9
Nov 10th, 2004
it runs ....

thannnnnnk u very much

and sorry for inconvenience....
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,566
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 705
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: generate random question

 
0
  #10
Nov 10th, 2004
>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'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC