C高手们帮忙看一下这个程序错在哪里?

来源:百度知道 编辑:UC知道 时间:2024/05/22 14:48:05
#include<stdio.h>
void main()
{
int a,b,sum,leap;
char c,z;
do
{
scanf("%d%c%d\n",&a,&c,&b); /*输入公式,其中c存放的是运算符*/
if(c=='+') sum=a+b; /*如果c存放的是+号,则执行加法运算*/
else if(c=='-') sum=a-b; /*如果c存放的是-号,则执行减法运算*/
else if(c=='*') sum=a*b; /*如果c存放的是*号,则执行乘法运算*/
else if(c=='/') sum=a/b; /*如果c存放的是/号,则执行除法运算*/
printf("%d%c%d=%d\n",a,c,b,sum); /*输出出运算后的结果*/
printf("go on (Y/N):\n"); /*输出提示信息,问是否继续*/
scanf("%c",&z); /*输入回答信息*/
/*如果输入的是字母给leap赋值*/
if(z=='Y'||z=='y')
leap=1;
else if(z=='N'||z=='n')
leap=0;
} while(leap); /*查看leap的值以确定循环是否继续,*/
/*如前面输入的是字母Y或y,则循环继续*/
}
谢谢你啦我终于做出了还是你给我的思路呵呵谢谢啦!
这是我改的有点不足的地方就是我
当我按了除Y和N其它键可以进入go on ?(Y/N):
问题出来了就是:我想这个程序一运行就显示的不是go on?(Y/N)?这个语句?而是想第一次运行的时候想出现
Please input first number:这条语句帮忙帮我

用这个试一试吗,这个还需要修改的更好,特别除法的时候会丢失数据的

#include <stdio.h>

main()
{
int fir_num;
int sec_num;
int reslut;
char oper;

system("cls");

printf("Input the first number:");
scanf("%d", &fir_num);

printf("Input the operator:");
fflush(stdin);
oper = getchar();

printf("Input the second number:");
scanf("%d", &sec_num);

switch(oper)
{
case '+' : reslut = fir_num + sec_num;
break;
case '-' : reslut = fir_num - sec_num;
break;
case '*' : reslut = fir_num * sec_num;
break;
case '/' : if (sec_num == 0)
{
printf("\nThe second number can't be ZERO!\n\n");
system("pause");
exit(0);
}