急急急!! c语言编程! 下午交 在线等!!! 谢谢!

通过输入两个加数给学生一道加法运算题,如果答案正确,显示Right!否则提示重做,显示not correct!try again!,最多给三次机会,如果三次仍未做对,则显示 Not correct!You have try three times!Test over程序结束。

#include<stdio.h>
#include <stdlib.h>
#include <time.h>
int main()
{
int a,b,c;
printf("Input first number:");
scanf("%d",&a);
printf("Input second number:");
scanf("%d",&b);

int count=1;
while(1)
{
printf("%d + %d = ",a,b);
scanf("%d",&c);
if(c==a+b)
{
printf("Ringt!\n");
return 0;
}
else if(count==3)
{
printf("Not correct!You have try three times!Test over\n");
return 0;
}
printf("not correct!try again!\n");
count++;
}
}
温馨提示:内容为网友见解,仅供参考
第1个回答  2009-11-27
#include <stdio.h>
void main()
{
int a,b,c,c2;
int chances=3;
printf("Input two numbers:");
scanf("%d%d",&a,&b);
c=a+b;
while(chances-->0)
{
printf("%d+%d=",a,b);
scanf("%d",&c2);
if(c==c2)
{
printf("Right!\n");
break;
}
else
{
if(chances==0)
printf("Not correct! You have try three times! Test over.\n");
else
printf("Not Correct! Try again! %d chanecs left!\n",chances);
}
}
getchar();
}
第2个回答  2009-11-27
#include <stdio.h>

void main()
{
int a, b ,sum ,temp , i = 0 ;
printf("Please input two numbers.\n");
scanf("%d %d",&a,&b);
sum = a + b;
printf("%d + %d = ? Please input the answer.\n");
while(i < 3)
{
scanf ("%d",&temp);
if(temp != sum )
printf("not correct! try again!\n");
else
{ printf("Right!\n");break;}
i++;
}
if(temp!=sum)
printf("Not correct! You have try three times! Test over \n");
}

可能 不是 最好的
以我的经验
只能写成这样
第3个回答  2009-11-27
//---------------------------------------------------------------------------

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main(void)
{
int ws=0,a,b,c;
srand(time(NULL));
printf("%d+%d=",a=rand()%100,b=rand()%100);
if (scanf("%d",&c),c==a+b) {
printf("Right!\n");
}
else {
do
{
if (++ws==3) puts("Not correct!You have try three times!Test over");
else{
printf(" not correct!try again!\n");
printf("%d+%d=",a,b);
if (scanf("%d",&c),c==a+b) printf("Right!\n");
}
}while (c!=a+b&&ws<3);
}
return 0;
}
//---------------------------------------------------------------------------
相似回答
大家正在搜