| | |
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 |
* ansi api array arrays binarysearch calculate centimeter changingto char character convert copyanyfile copypdffile creafecopyofanytypeoffileinc createcopyoffile createprocess() csyntax directory dynamic fflush file floatingpointvalidation forloop frequency function getlasterror getlogicaldrivestrin givemetehcodez grade graphics gtkgcurlcompiling gtkwinlinux highest histogram homework i/o inches include infiniteloop input intmain() iso keyboard km linked linkedlist linux linuxsegmentationfault list logical_drives looping loopinsideloop. lowest match matrix microsoft mqqueue mysql oddnumber odf open opendocumentformat openwebfoundation pdf posix power program programming pyramidusingturboccodes radix read recursion recv recvblocked repetition reversing scanf scheduling segmentationfault send shape single socketprogramming stack standard strchr string suggestions test threads turboc unix urboc user variable whythiscodecausesegmentationfault win32api windows.h windowsapi






