help why does cnt not reset to 1??
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 hte wrong words.
int main()
{
int num1, num2, awn;
int cnt=1, right=0, wrong = 0, percentage=0;
srand(time(NULL));
num1 = 1+ rand () % 9;
num2 = 1+ rand() % 9;
while ( cnt != -1 ){
printf ("How much is %d times %d?", num1, num2 );
scanf ("%d", &awn );
if ( riwo (num1, num2, awn ) == 1) {
num1 = 1+ rand() %9;
num2 = 1+ rand() %9;
rightwords();
right++; }
else {
wrongwords();
wrong++; }
{ percentage = ((10 - wrong)*100)/10;
if((cnt == 10 ) && ( percentage <= 50 )){
printf ("Ask you instructor for extra help\n");
break; }
if ( cnt== 10 ){
cnt =1; }
}
++cnt; }
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;
}
}
well the problem here is when cnt == 10 it checks if the percentage is less that 50 ..So i wanted to reset cnt back to 1 so i used if ( cnt == 10 ) then cnt = 1;
am i wrong where am i wrong??? help me out :confused:
Re: i want to reset it to 1
Quote:
Originally posted by datainjector
... is my code okay
Why not run it and see.... testing a program is just as much a part of development as writing the actual code :)