I need help again. I've gotten better =)
ok I'm really sleepy and coding as fast as i can to finish. this is what i got. I got to create a program to help kids develop math skills and encourage them. what I'm trying to do is create a loop and then break it. loop will make the child input another answer to the previously given question unless he doesn't want to---which is where the break comes in. sorry if its a little messy, i'm new
OK
Code:
#include <stdio.h>#include <stdlib.h>
#include <time.h>
#include <math.h>
#include <ctype.h>
int main(void);
void correctMessege(void);
void incorrectMessege(void);
void again(void);
int main(void)
{
int num1, num2, operation, answer;
num1 = rand() % 4;
num2 = rand() % 4;
printf("...................................... HELLO!! .................................\n");
printf("................ LET'S ...................................... PLAY .............\n\n");
printf(" PRESS>> 1 to ADDING PRESS>> 2 to SUBTRACT\n\n");
printf(" PRESS>> 3 to MULTIPLY PRESS>> 4 to DIVIDE\n\n");
printf(" PRESS>> 5 if your really SMART \n");
scanf("%d", &operation );
if(operation == 1)
{
answer = num1 + num2;
printf("How much is %d + %d?\n", num1, num2);
do{ /*here i need help*/
scanf(" %d",&answer);
if(num1+num2 !=answer)
{
incorrectMessege();
continue;
}
else if(num1+num2 ==answer)
{
correctMessege();
again(); /*trying to make this string break the loop, string is further down*/
}}while(0==0);
}
else if(operation == 2)
{
answer = num1 - num2;
printf("How much is %d - %d?\n", num1, num2);
do {
scanf(" %d",&answer);
if( num1-num2 !=answer )
{
incorrectMessege();
continue;
}
else if( num1-num2 ==answer )
{
correctMessege();
again();
}}while(0==0);
}
else if(operation == 3)
{
answer = num1 * num2;
printf("How much is %d * %d?\n", num1, num2);
while(){ /*ignore this i was messing around i'll fix it once i get it down on the first one*/
scanf(" %d",&answer);
if( num1*num2 !=answer )
{
incorrectMessege();
continue;
}
else if( num1*num2 ==answer )
{
correctMessege();
again();
}};
}
else if(operation == 4)
{
answer = num1 / num2;
printf("How much is %d / %d?\n", num1, num2);
do {
scanf(" %d",&answer);
if( num1/num2 !=answer )
{
incorrectMessege();
continue;
}
else if( num1/num2 ==answer )
{
correctMessege();
again();
}}while(0==0);
}
return 0;
}
void correctMessege(void)
{
int select;
select = 1 +rand() % 5;
switch (select)
{
case 0:
printf( "Very good!");
break;
case 1:
printf( "Excellent!");
break;
case 2:
printf( "Nice work!");
break;
case 3:
printf( "Keep up the good work!");
break;
case 4:
printf( "Your awesome!");
break;
}
}
void incorrectMessege(void)
{
int select;
select = 1 +rand() % 5;
switch (select)
{
case 0:
printf( "No. Please try again.");
break;
case 1:
printf( "Wrong. Try once more.");
break;
case 2:
printf( "Don't give up!");
break;
case 3:
printf( "No. Keep trying.");
break;
case 4:
printf( "I believe in you!");
break;
}
}
void again(void) /*string is here*/
{
char pop;
printf("Another one? (y/n):\n");
scanf("%c",&pop);
if(pop=='y')
{
continue;
}
else if(pop=='n')
{
break;
}
}