你整个程序捋一下就是:
先由使用者输入两个加数,然后让计算机求和。
do-while 语句中是一只让计算机计算a+b,再把值赋给sum,条件是计算机计算出来的sum是错的。所以肯定运行不对。
/*
你好好看你的代码:
学生从哪里输入答案?!
你有让输入答案的代码吗?
*/
#include
#include
int main()
{
int a,b,sum;
printf("输入两个数字:");
scanf("%d%d",&a,&b);
while( 1 )
{
printf("输入答案: " );
scanf( "%d", &sum );
if ( sum == a+b )
{
printf("正确\n");
break;
}
else
printf("错误,try again\n");
}
return 0;
}
到底是让谁计算两个数的和呢????计算机还是学生啊???
#include
#include
int main()
{
int a,b,sum;
printf("please input two number and your result sum:");
scanf("%d%d%d",&a,&b,&sum);
while(sum != a+b)
{
printf("错误,try again\n");
scanf("%d",&sum);
}
printf("正确\n");
return 0;
}
#include
int main()
{
int a,b,sum;
printf("please input two number:");
scanf("%d%d",&a,&b);
sum=a+b;
printf("\n");
scanf("%d", &sum);
if(sum!=a+b);
printf("错误,try again\n");
else
printf("正确");
return 0;
}
#include
#include
int main()
{
int a,b,sum;
printf("please input two number:");
scanf("%d%d",&a,&b);
while( 1 )
{
printf("input answer: " );
scanf( "%d", &sum );
if ( sum == a+b )
{
printf("正确\n");
break;
}
printf("错误,try again\n");
}
return 0;
}