帮忙看一下这段c++代码的错误~谢谢~

来源:百度知道 编辑:UC知道 时间:2024/05/16 22:11:15
我用的是vc++6.0
# include <iostream.h>
# include <conio.h>

void main()
{
cout <<"please input the b key to hear a bell.\n";

char ch=getche();
if (ch=='b')
cout <<'\a';
else

if (ch=='\n')
cout <<"what a boring\n";
else
cout <<"bye!\n";

}
先是什么都没出现,按b则出现响铃和please input the b key to hear a bell,按任意键退出!
如果先按的不是b,则出现please input the b key to hear a bell并且不响铃,按任意键退出!
后边的输出语句what a boring和bye!没有输出!
对不起,好像不是这两个地方错了啊!
谢谢jczff 啊!不过现在倒是先出句子了,但无论我按何键,它都不会出现 what a boring 句子了……

#include<iostream>
using namespace std; //加了这个
#include<conio.h>
void main()
{
cout <<"please input the b key to hear a bell.\n";

char ch=getche();
if (ch=='b')
cout <<'\a';
else

if (ch=='\n') //\n 应该为换行,在键盘里面有这个键吗,我猜你的意思时想按了回车键输出<<"what a boring\n"; 你换成\r试试
cout <<"what a boring\n";
else
cout <<"bye!\n";

}

if (ch=='\n') 不对吧

getch不是getche
if (ch==('\n'))