Yo..I have a problem with my programm. I need a lil assistance…The part that I cant do is the random question part..If I choose five it does not give me the random question ..How would I do that?
ThanksCode:#include <stdio.h> #include <time.h> #include <stdlib.h> int riwo ( int ,int, int, int ); //function prototype . void rightwords ( void ); //function for the right words. void wrongwords (void ); //function for hte wrong words. int main() { int num1, num2, awn,type; int diff; srand(time(NULL)); printf ("Enter the level of difficulty.1 for one-digit integers, and 2 for\ntwo-digit integers: "); scanf ("%d", &diff ); if ( diff == 1 ){ num1 = 1+ rand () % 9; num2 = 1+ rand() % 9; } else { num1 = 10+rand() %99; num2 = 10+rand() %99;} printf ("\nEnter the type of arithmetic problem you would like to use: \n" "1)<---Addition\n" "2)<---Subtraction\n" "3)<---Multiplication\n" "4)<---Division\n" "5)<---random ( Addition, Subtraction, Multiplication and Division\n" "\nPlease choose from thefollowing: "); scanf ("%d", &type ); for (;;){ switch ( type){ case 1: printf ("How much is %d plus %d?", num1, num2 ); scanf ("%d", &awn ); break; case 2: printf ("How much is %d minus %d?", num1, num2 ); scanf ("%d",&awn ); break; case 3: printf ("How much is %d times %d?", num1, num2 ); scanf ("%d", &awn ); break; case 4: printf ("How much is %d divided by %d?", num1, num2 ); scanf ("%d", &awn ); break; case 5: type = 1+rand() % 4; break; } if ( riwo (num1, num2, awn,type ) == 1) { rightwords(); if ( diff == 1){ num1 = 1+ rand() %9; num2 = 1+ rand() %9; } else{ num1 = 10+rand() % 99; num2 = 10+rand() % 99; }} else wrongwords(); } system ("PAUSE"); return 0; } int riwo (int a, int b, int tot, int ty ) { if ( ty == 1 ){ if ( tot == a+b ) return (1); else return (0); } if ( ty == 2) { if ( tot == a-b ) return (1); else return (0); } if (ty == 3 ) { if ( tot == a*b ) return (1); else return (0);} if ( ty == 4 ) { if ( tot == b/a ) return (1); else return (0); } } void rightwords( void ) { int right; right = 1+rand () % 4; switch ( right ){ case 1: printf ("Very good!\n"); break; case 2: printf ("Excellent!\n"); break; case 3: printf ("Nice work!\n"); break; case 4: printf ("Keep up the good work!\n"); break; } } void wrongwords ( void ) { int wrong; wrong = 1+rand() % 4; switch ( wrong ){ case 1: printf ("No. Please try again.\n"); break; case 2: printf ("Wrong. Try once more.\n"); break; case 3: printf ("Don't give up!\n"); break; case 4: printf ("No.keep trying\n"); break; } }



LinkBack URL
About LinkBacks



{