首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

C++新手求教,还望各位老师多多指点!解决方法

2012-09-10 
C++新手求教,还望各位老师多多指点!char the_Exitcout Are you sure eixt? y/ncin the_Exitif

C++新手求教,还望各位老师多多指点!
char the_Exit;
cout << "Are you sure eixt? y/n";
cin >> the_Exit;
if (the_Exit == n)
break;
else
continue;
我想通过这段程序来实现退出功能。为什么会报错呢?如何才能完成输入y/n退出呢?

[解决办法]

C/C++ code
#include <iostream>using namespace std;int main(){    char the_Exit;        char y = 'n';    while (true)    {        cout << "Are you sure eixt? y/n  \n";        cin >> the_Exit;        if (the_Exit == y)            break;        else            continue;    }}
[解决办法]
#include <iostream>

using namespace std;

int main()
{


char the_Exit;

char y = 'n';
while (true)
{
cout << "Are you sure eixt? y/n \n";
cin >> the_Exit;

if (the_Exit == y)
continue;
else
break;
}

}
[解决办法]
你的变量类型好乱啊,编译器没有报错?再设一个整型变量吧。还有按你写的,continue语句也没什么意义,不用写。下面是我写的,Visual c++ 6.0 通过了,楼主参考一下。
#include <iostream>
int main()
{
 using namespace std;
 char the_Exit;
 char y,n;
 int Exit;
 while (true)
 {
 cout << "Are you sure eixt? y/n"<<endl;
 cin >> the_Exit;

 if (the_Exit=='y')
Exit=0;
 else
Exit = 1;

 if (Exit==0)
break;
 }
 return 0;
}

最好用下面这个,很简洁
#include <iostream>
using namespace std; 
int main()

 char the_Exit;
 char y,n;
 while (true)
 {
 cout << "Are you sure eixt? y/n"<<endl;
 cin >> the_Exit;

 if (the_Exit=='y')
break;
 }
 return 0;
}

热点排行