怎么用C++编一个问答程序啊

nidearong 2009-04-07 04:41:11
怎么用C++编一个问答程序啊,,,,我用FOR语句去控制一个问答循环可是 却是个死循环 郁闷死了
在下是个刚刚学编程的大学生,,,,,请给位多多指教。。。。。
...全文
455 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
nyeboy123 2009-04-08
  • 打赏
  • 举报
回复
//调用
void main()
{
bool b=true;
while (b)
{
b=Question();
}
}
int Question(int QuestionIndex)
{
int index=QuestionIndex;
std::string question=LoadQuestion(index);//从数据库加载指定编号的问题
vector<std::string> answervec=LoadAnswer(index);//从数据库加载备选项
std::string rightanswer=LoadRightAnswer(index);//从数据库加载正确答案
//显示问题
//获取用户输入的答案
//验证答案是否正确
if (//答案错误)
{
//继续等待直到用户输入正确答案
}
//返回是否答对
}
dxx190j 2009-04-08
  • 打赏
  • 举报
回复
getchar()
putchar()
sunzuyi 2009-04-07
  • 打赏
  • 举报
回复
if语句里= 都改成==
nidearong 2009-04-07
  • 打赏
  • 举报
回复
#include<iostream>
using namespace std;
int main()
{
int i;
char ch;
begin: cout<<"提示:在本次提问中,Y代表YES,N代表NO,明白后请输入Y,不明白请重看"<<endl;
cin>>ch;
if (ch='y')
/*cout<<"你好吗?"<<endl;*/
for(i=0;i<=7;i++)
{
{
if(i=1)
if (ch='y')
cout<<"我知道"<<endl;
else if (ch='n')
cout<<"继续努力"<<endl;
/*continue ;*/
}
{
if(i=2)
cout<<"你有女朋友吗?"<<endl;
if(ch='y')
cout<<"你说谎"<<endl;
else if(ch='n')
cout<<"可怜的孩子"<<endl;
/*continue ;*/
}

{
if(i=3)
cout<<"我知道你的名字,你相信吗?"<<endl;
if(ch='y')
cout<<"别相信陌生人"<<endl;
else if(ch='n')
cout<<"我是xxx"<<endl;
/*continue ;*/
}

{
if(i=4)
cout<<"你喜欢玩游戏吗?"<<endl;
if(ch='y')
cout<<"我知道,我是xxx"<<endl;
else if(ch='n')
cout<<"你说谎,我是xxx"<<endl;
continue ;
}

{
if(i=5)
cout<<"你喜欢xxx吗?"<<endl;
if(ch='y')
cout<<"诚实的孩子"<<endl;
else if(ch='n')
cout<<"你没有玩过雷电吗?,太差了"<<endl;
/*continue ;*/
}

{
if(i=6)
cout<<"你喜欢xxx吗?"<<endl;
if(ch='y')
cout<<"唉,只会暗恋的孩子"<<endl;
else if(ch='n')
cout<<"我有同感"<<endl;
/*continue ;*/
}


}

/*else if(ch='n')
goto begin ;*/


return 0;


}
这是我写的 不知道错在那里 各位帮帮忙
sagegz 2009-04-07
  • 打赏
  • 举报
回复
多看基础!
  • 打赏
  • 举报
回复
for(...)
{
cout<<".."<<endl;
cin<<..;
cout<<"q for quit,else go on"<<endl;
cin<<a;
if(a=='q')
break;
}

liying520 2009-04-07
  • 打赏
  • 举报
回复
你要循环问答吗?具体点
有几个问题?

不是死循环的话。就
for(int i=0;i<3;i++)
{
int x;
printf("1+1=?");
scanf("%u",x);
printf("输入的答案是:%u",x);
}

很显然你用这种方法只是循环回答同一个问题
如果要在里面多个问题就要switch(i)
或者if(i==一个数)
这样多麻烦?
干嘛要在for循环里?
直接按个输出和接受问题不就好了
lanneret1234 2009-04-07
  • 打赏
  • 举报
回复
用break
ryfdizuo 2009-04-07
  • 打赏
  • 举报
回复
so easy !

65,211

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧