its almost done...it compiles and works almost perfect....well when I write a good answer after doing it wrong it doesnt print a positive response..instead it displays the menu...what i have to do in order it to display a positive response like "Good job" before displaying the menu?? thanks
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
void message(int);
int main()
{
int x, y, chosenoption, answer1, response, option;
srand( time( NULL ) );
printf( "\nLet's learn how to multiply.\n" );
printf( "\nChoose an option from below:\n" );
printf( "Type 1 for a single digit multiplication\n" );
printf( "Type 2 for a two digit multiplication\n" );
printf( "Type -1 to end program.\n \n");
scanf("%d", &chosenoption);
while(chosenoption != -1) {
if (chosenoption == 1){
x = ( rand() % 10 );
y = ( rand() % 10 );
printf( "\nHow much is %d times %d? \n", x,y );
scanf("%d", &answer1);
}
if (chosenoption == 2){
x = 10 + ( rand() % 90 );
y = 10 + ( rand() % 90 );
printf( "\nHow much is %d times %d? \n", x,y );
scanf("%d", &answer1);
}
if ( x * y == answer1 )
message( 1 ); /* Success */
else
message( 0 ); /* Failure */
while ( x * y != answer1 ) {
printf( "\nHow much is %d times %d? \n", x,y );
scanf("%d", &answer1);
message (0);
}
printf( "\n\nLet's learn how to multiply.\n" );
printf( "\nChoose an option from below:\n" );
printf( "Type 1 for a single digit multiplication\n" );
printf( "Type 2 for a two digit multiplication\n" );
printf( "Type -1 to end program.\n \n");
scanf("%d", &chosenoption);
}
return 0;
}
void message( int answer )
{
int option;
option = 1 + ( rand() % 4 );
if ( answer == 1 ) {
switch (option) {
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;
}
}
if ( answer == 0 ) {
switch (option) {
case 1:
printf( "No. Please try again.\n" );
break;
case 2:
printf( "Wrong. Try one more time.\n" );
break;
case 3:
printf( "Don't give up.\n" );
break;
case 4:
printf( "No. Keep trying.\n" );
break;
}
}
}