I want to modify my program so that it can coun the number of correct and incorrect responses typed by the student.After the student types 10 awnsers, my program should calculate the percentage of the correct responses.If the percentage is lower than 75 percent, your program should print "Please ask you instructor for extra help" and then terminate..
My code:
Code:
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
int riwo ( int ,int, int ); //function prototype .
void rightwords ( void ); //function for the right words.
void wrongwords (void ); //function for the wrong words.
void tutorhelp ( int, int, int ); //function for calculating the percentage.
int main()
{
int num1, num2, awn;
srand(time(NULL));
num1 = 1+ rand () % 9;
num2 = 1+ rand() % 9;
while (riwo(num1, num2,awn) == 0) {
printf ("How much is %d times %d: ", num1 , num2);
scanf ("%d", &awn );
if ( riwo(num1, num2, awn) == 1) {
rightwords();
while ( riwo( num1, num2, awn) == 1){
num1 = 1+ rand () % 9;
num2 = 1+ rand() % 9;
printf ("How much is %d times %d: ", num1 , num2);
scanf ("%d", &awn );
if ( riwo ( num1, num2, awn) == 1 ){
rightwords();}
} }
wrongwords();
tutorhelp(num1, num2, awn);
}
system("PAUSE");
return 0;
}
int riwo (int a, int b, int tot )
{
if ( tot == a*b )
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;
}
}
void tutorhelp ( int x, int y, int z )
{
int cnt, addwrong, addright, percentage, totright, totwrong;
percentage = ((addright- addwrong) *100) /10;
if ( riwo (x, y, z) ==1 )
totright += addright;
else
totwrong += addwrong;
if ( totright + totwrong == 10 ){
percentage = ((totright- totwrong) *100) /10;
if ( percentage <= 75 ){
printf ("Please ask your instructor for extra help");
}}}
Thanks alot