这个小程序错在哪里?

[复制链接]
查看11 | 回复3 | 2006-12-15 17:05:25 | 显示全部楼层 |阅读模式
#include "stdio.h"#include "conio.h"main() { float x,y,n;char ch; renew:printf("please enter 2 numbers:");scanf("%f,%f",&x,&y);printf("%f%f",x,y);printf("enter the +-*/:") ;scanf("%c",&ch);scanf("%c",&ch);switch(ch) { case '+':n=x+y;break; case '-':n=x-y;break; case '*':n=x*y;break; case '/':n=x/y; break;default:printf("renew");printf("\n");gotorenew;} printf("%5f",n);getch();} 你的scanf("%c",&ch);接受的是回车符号,所以那个n是一个随机的数据,你在后面再添加一个scanf("%c",&ch);就可以了!!
回复

使用道具 举报

千问 | 2006-12-15 17:05:25 | 显示全部楼层
你没有用getchar();语句在SCANF前加上这个句子就OK了
回复

使用道具 举报

千问 | 2006-12-15 17:05:25 | 显示全部楼层
scanf("\n....
回复

使用道具 举报

千问 | 2006-12-15 17:05:25 | 显示全部楼层
getche
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行