# include<stdio.h>int main(){char system;int n,remain,result;printf("input a number:\n");scanf("%d",&n);printf("input a system:\n");scanf("%c\n",&system);//这里按理说输入的是字母,调试时不是,why? printf("the new number is:\n");//上一步到底哪里错了啊? if(result!=0&&system=='B'){ remain=n%2; result=n/2; printf("%3d",remain); n=result;}else if(result!=0&&system=='O'){ remain=n%8; result=n/8; printf("%3d",remain); n=result;}else if(result!=0&&system=='H'){ remain=n%16; result=n/16; printf("%3d",remain); n=result;}else{ printf("wrong character or 0,input again.\n");}
getch();}
可是输入语句没用\n的话还是不对啊???
加了fflush还是没有用,为什么
追答# include
int main()
{
char system,free;
int n,remain,result;
scanf("%d%c%c",&n,&free,&system);
printf("the new number is:\n");//上一步到底哪里错了啊?
if(result!=0&&system=='B')
{ remain=n%2;
result=n/2;
printf("%3d",remain);
n=result;
}
else if(result!=0&&system=='O')
{ remain=n%8;
result=n/8;
printf("%3d",remain);
n=result;
}
else if(result!=0&&system=='H')
{ remain=n%16;
result=n/16;
printf("%3d",remain);
n=result;
}
else
{ printf("wrong character or 0,input again.\n");
}
return 0;
}
这是满足你这道题目的输入方式
我原来的程序添加查看的时候,B system是这个,为什么啊?
追答66是字符B对应的ASCII码
追问为什么会出现ASCII码?那后面用if判断的时候怎么写?
跪求解释
追答你现在这样写是没有错误的,每一个字符都有一个对于的ASCII码,你可以自行百度ASCII码表,因为char类型可以强制转换为int类型
比如:
char a = 'B';
int b = (int)a;
此时b就变成了66
但是执行不了啊
system我输入的是B,但是程序在判断的时候就不是B可
怎么办
追答不会吧,我本地检验了一下,是可以执行的
追问骗人的吧,截图来啊
追答这是你的程序的执行效果
在来几个输入输出??
再来几个试试
可能我们编译器不同
本回答被提问者采纳不是啊 还是不对
追答那你再在scanf("%c",&system);的前面加个清除缓存的试试fflush(stdin);
追问还是不对啊