求c語言大神指導 第二題!

題目:

求c語言大神指導 第二題!
Write a program that would be used to teach multiplication to children.Your program should first ask the user to enter two numbers (A and B).Then it would ask the user to enter the result of A x B (i.e.product of A and B).If the user gets it right,then the program asks the user if he/she wants to play again.If yes,then again start by entering two new numbers for A and B.If no,then end the program.
However,if the user inputs an incorrect result for A x B your program will give them two more chances to get it right.If they fail three times,then start again by asking them to enter two new numbers for A and B.

解答:

#include <stdio.h>
#include <stdlib.h>
int main(int argc,char *argv[])
{
int a,b,ans;
int count=0;
char ch;
while(1)
{
printf("please input num A and num B:");
scanf("%d %d",&a,&b);
fflush(stdin);
printf("please input the ans of A*B:");
LABLE:scanf("%d",&ans);
fflush(stdin);
if(a*b==ans)
{
printf("do you want to play again?please input y for yes,n for no:");
scanf("%c",&ch);
fflush(stdin);
if(ch=='y')
{
count=0;
continue;
}
else if(ch=='n')
{
break;
}
}
else
{
count++;
if(count<3)
{
printf("your answer is wrong,please reInput your answer:");
goto LABLE;
}
else
{
printf("You have already answered incorrectly three times, calculate the next question.\n");
continue;
}
}
}


system("PAUSE");
return 0;
}

名師點評:

信ShinehH

添加新評論

暱稱
郵箱
網站