Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
void correctResponse(void);
void incorrectResponse (void);
void multiplication( void ); // function prototype
int main( void )
{
int correct, incorrect;
srand( time( NULL ) ); // seed random number generator
multiplication(); // begin multiplication practice
} // end main
void correctResponse(void)
{
int correct;
correct= correct + 1;
switch(rand()%4)
{
case 0:
puts("Very good!");
break;
case 1:
puts("Excellent!");
break;
case 2:
puts("Good Job!");
break;
case 3:
puts("You're Amazing!");
break;
}
}
void incorrectResponse(void)
{
int incorrect;
incorrect= incorrect + 1;
switch(rand()%4)
{
case 0:
puts("Nice Try");
break;
case 1:
puts("You Suck!");
break;
case 2:
puts("Maybe Next Time!");
break;
case 3:
puts("Terrible!");
break;
}
}
// multiplication produces pairs of random numbers and
// prompts user for product
void multiplication( void )
{
int correct, incorrect;
int x; // first factor
int y; // second factor
int response = 0; // user response for product
int total;
// use sentinel-controlled repetition
puts( "Enter -1 to end." );
// loop while sentinel value not read from user
while ( response != -1 ) {
x = rand() % 10; // generate 1-digit random number
y = rand() % 10; // generate another 1-digit random number
printf( "How much is %d times %d? ", x, y );
scanf( "%d", &response );
// loop while not sentinel value or correct response
while ( response != -1 && response != x * y ) {
incorrectResponse();
scanf( "%d", &response );
} // end while
// correct response
if ( response != -1 ) {
correctResponse();
} // end if
} // end while
total= (correct/(incorrect+correct));
if (total >= .75) {
printf("Congratulations, You are ready for the next level!");
}
else {
printf("Please ask your Teacher for extra help.");
}
puts( "That's all for now. Bye." );
} // end function multiplication
// It keeps crashing. How do I compile the responses into a grade? Thank you!