大神请进,C语言问题
#include<stdio.h>floata=0,b=0,sum=0;charpd;intpd2;intmain(void){do{printf("加法计算请输入1\n...
#include<stdio.h>
float a=0, b=0, sum=0;char pd;int pd2;
int main(void){ do { printf("加法计算请输入1\n减法计算请输入2\n乘法计算请输入3\n除法计算请输入4"); printf("\n请输入并回车:"); scanf_s("%d",pd2); if (pd2 == "1") { sum = jiafa(a, b); printf("%f + %f = %f", a, b, sum); a = 0, b = 0, sum = 0; } else { if (pd2 == "2") { sum = jianfa(a, b); printf("%f - %f = %f", a, b, sum); a = 0, b = 0, sum = 0; } else { if (pd2 == "3") { sum = chengfa(a, b); printf("%f × %f = %f", a, b, sum); a = 0, b = 0, sum = 0; } else { if (pd2 == "4") { sum = chufa(a, b); printf("%f ÷ %f = %f", a, b, sum); a = 0, b = 0, sum = 0; } else { printf("您输入错误,请重启程序"); } } } } printf("是否返回?(Y/N):"); scanf_s("%s", pd);
} while (pd == "Y");}
int jiafa(float x, float y){ int z = 0; printf("请输入加数:"); scanf_s("%f",x); printf("请输入加数:"); scanf_s("%f", y); z = x + y; return z;}int jianfa(int x, int y){ int z = 0; return z;}int chengfa(int x, int y){ int z = 0; return z;}int chufa(int x, int y){ int z = 0; return z;}
//------------------------------------------------------------------------------------------------------------------------
请问 为什么输入1后(2、3、4不计)便无响应? 展开
float a=0, b=0, sum=0;char pd;int pd2;
int main(void){ do { printf("加法计算请输入1\n减法计算请输入2\n乘法计算请输入3\n除法计算请输入4"); printf("\n请输入并回车:"); scanf_s("%d",pd2); if (pd2 == "1") { sum = jiafa(a, b); printf("%f + %f = %f", a, b, sum); a = 0, b = 0, sum = 0; } else { if (pd2 == "2") { sum = jianfa(a, b); printf("%f - %f = %f", a, b, sum); a = 0, b = 0, sum = 0; } else { if (pd2 == "3") { sum = chengfa(a, b); printf("%f × %f = %f", a, b, sum); a = 0, b = 0, sum = 0; } else { if (pd2 == "4") { sum = chufa(a, b); printf("%f ÷ %f = %f", a, b, sum); a = 0, b = 0, sum = 0; } else { printf("您输入错误,请重启程序"); } } } } printf("是否返回?(Y/N):"); scanf_s("%s", pd);
} while (pd == "Y");}
int jiafa(float x, float y){ int z = 0; printf("请输入加数:"); scanf_s("%f",x); printf("请输入加数:"); scanf_s("%f", y); z = x + y; return z;}int jianfa(int x, int y){ int z = 0; return z;}int chengfa(int x, int y){ int z = 0; return z;}int chufa(int x, int y){ int z = 0; return z;}
//------------------------------------------------------------------------------------------------------------------------
请问 为什么输入1后(2、3、4不计)便无响应? 展开
4个回答
展开全部
scanf_s("%d", & pd2);//这里少了&符号 后面的其他scanf_s输入也要加上
if (pd2 == 1) //整数常量不能再引号,有引号表示字符串,后面的其比较也要改一下
scanf("%c", &pd ); //读字符用%c
} while (pd == 'Y'); //字符常量要用单引号引起来!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
main函数里的 scanf_s("%d",pd2);
改为:scanf_s("%d",&pd2);试试
希望对你有帮助
改为:scanf_s("%d",&pd2);试试
希望对你有帮助
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
printf("\n请输入并回车:");
scanf_s("%d",pd2);
=>
差一个&
scanf_s("%d",&pd2);
scanf_s("%d",pd2);
=>
差一个&
scanf_s("%d",&pd2);
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询