this is supposed to be a multiplication program.. it compiles well but when I run it an indefinite loop is caused. can't see where. heeelp! i've been doing this for 2 days!....how I create the responses with a function void message(answer) ????? thanks...
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main()
{
int x, y, chosenoption, answer1, response, option;
srand( time( NULL ) );
printf( "\nLet's learn how to multiply.\n" );
printf( "Choose 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( "How much is %d times %d? \n", x,y );
scanf("%d", &answer1);
}
if (chosenoption == 2){
x = 10 + ( rand() % 90 );
y = 10 + ( rand() % 90 );
printf( "How much is %d times %d? \n", x,y );
scanf("%d", &answer1);
}
if (answer1 == x*y )
response = 1;
else
response = 0;
option = 1 + ( rand() % 4 );
while ( response == 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;
}
}
while ( response == 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;
}
}
printf( "Let's learn how to multiply.\n" );
printf( "Choose 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;
}