| | |
generate random question
![]() |
•
•
Join Date: Nov 2004
Posts: 5
Reputation:
Solved Threads: 0
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 ,,,
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
>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:
So use a series of if statements, do you know how to use those? :rolleyes:
C Syntax (Toggle Plain Text)
int r = rand() % N; if ( r == 0 ) /* First question */ else if ( r == 1 ) /* Second question */ ... else if ( r == N - 1 ) /* Nth question */
I'm here to prove you wrong.
•
•
Join Date: Nov 2004
Posts: 5
Reputation:
Solved Threads: 0
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);
}
#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);
}
C Syntax (Toggle Plain Text)
#include <stdio.h> #include <stdlib.h> int main() { int N = 3,counter,i; for(i=0;i<10;i++) { int r = rand() % N; 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++; } getchar(); } printf("your score is %d\n", counter); return 0; }
I'm here to prove you wrong.
![]() |
Similar Threads
- need help, need to generate 10 random numbers, such that their sum is less than 1 (C)
- Trying to find a better way to generate random numbers in Dev Pascal (Pascal and Delphi)
- Need to know how to create a database that will generate a random number (Database Design)
Other Threads in the C Forum
- Previous Thread: can anyone tell me how we restart the system using C Programming
- Next Thread: Slow CPU causes damage to robot
| Thread Tools | Search this Thread |
* adobe ansi api array asterisks binarysearch calculate centimeter changingto char character cm convert copyimagefile cprogramme creafecopyofanytypeoffileinc createcopyoffile csyntax database directory feet fflush fgets file floatingpointvalidation fork forloop frequency givemetehcodez grade gtkgcurlcompiling gtkwinlinux hacking highest histogram inches input intmain() iso kernel keyboard kilometer km linked linkedlist linux linuxsegmentationfault list locate looping loopinsideloop. lowest match microsoft mqqueue mysql number oddnumber odf opendocumentformat openwebfoundation owf pattern pdf performance posix probleminc process program programming radix recv recvblocked repetition research reversing scanf scheduling segmentationfault sequential single socket socketprograming socketprogramming stack standard string systemcall threads turboc unix urboc user variable voidmain() wab whythiscodecausesegmentationfault windows.h windowsapi






