程序对了~ 但是需要加一项

sunsold 2009-05-18 08:08:08
程序可以运行 但是我需要在这个程序的基础上增加一个 算总分的功能
每个问题有不同的分数 可以选择回答 然后回答完了 我想把他们都加起来 看一共得了多少分 这个功能怎么加进去?


#include <iostream>
#include <string>

using namespace std;

class trivia
{
public:
void question1();
void question2();
void question3();
void question4();
void question5();
int i;
};
void main()
{
trivia a;
int c;
string strinfo;
string ans;
do{
cout<<"输入你想回答问题的号码1-5"<<endl;
cout<<"the 1 is 2point, 2 is 3point ,3 is 5point, 4 is point,5 is 10point"<<endl;
cin>>c;
switch(c)
{
case 1:
{
cout<<"问题是"<<endl;
cout<<"Second largest city in Korea?"<<endl;
a.question1();
break;
}
case 2:
{
cout<<"问题是"<<endl;
cout<<"Fourth planet from the Sun?"<<endl;
a.question2();
break;
}
case 3:
{
cout<<"问题是"<<endl;
cout<<"National younger sister in Korea?"<<endl;
a.question3();
break;
}
case 4:
{
cout<<"问题是"<<endl;
cout<<"2002 FIFA World Cup winner?"<<endl;
a.question4();
break;
}
case 5:
{
cout<<"问题是"<<endl;
cout<<"Professor Yoo’s favorite actress?"<<endl;
a.question5();
break;
}
}
cout<<"你还想继续回答问题吗? y or n"<<endl;
cin>>ans;
}while(ans=="y");

}
void trivia::question1()
{
string string1;
cout<<"input your answer:"<<endl;
cin>>string1;
if(string1=="pusan")
cout<<"you are right,you can get 2 point"<<endl;
else
cout<<"you are wrong,the right answer is pusan"<<endl;
}
void trivia::question2()
{
string string2;
cin>>string2;
if(string2=="mars")
cout<<"you are right,you can get 3 point"<<endl;
else
cout<<"you are wrong,the right answer is pusan"<<endl;
}
void trivia::question3()
{
string string3;
cin>>string3;
if(string3=="yunakim")
cout<<"you are right,you can get 5 point"<<endl;
else
cout<<"you are wrong,the right answer is pusan"<<endl;
}
void trivia::question4()
{
string string4;
cin>>string4;
if(string4=="brazil")
cout<<"you are right,you can get 7 point"<<endl;
else
cout<<"you are wrong,the right answer is pusan"<<endl;
}
void trivia::question5()
{
string string5;
cin>>string5;
if(string5=="drew")
cout<<"you are right,you can get 10 point"<<endl;
else
cout<<"you are wrong,the right answer is pusan"<<endl;
}
...全文
52 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
sunsold 2009-05-18
  • 打赏
  • 举报
回复

#include <iostream>
#include <string>

using namespace std;

class trivia
{
public:
void question1();
void question2();
void question3();
void question4();
void question5();
int i;
};
void main()
{
trivia a;
int c;
string strinfo;
string ans;
do{
cout<<"输入你想回答问题的号码1-5"<<endl;
cout<<"the 1 is 2point, 2 is 3point ,3 is 5point, 4 is point,5 is 10point"<<endl;
cin>>c;
switch(c)
{
case 1:
{
cout<<"问题是"<<endl;
cout<<"Second largest city in Korea?"<<endl;
a.question1();
break;
}
case 2:
{
cout<<"问题是"<<endl;
cout<<"Fourth planet from the Sun?"<<endl;
a.question2();
break;
}
case 3:
{
cout<<"问题是"<<endl;
cout<<"National younger sister in Korea?"<<endl;
a.question3();
break;
}
case 4:
{
cout<<"问题是"<<endl;
cout<<"2002 FIFA World Cup winner?"<<endl;
a.question4();
break;
}
case 5:
{
cout<<"问题是"<<endl;
cout<<"Professor Yoo’s favorite actress?"<<endl;
a.question5();
break;
}
}
cout<<"你还想继续回答问题吗? y or n"<<endl;
cin>>ans;
}while(ans=="y");

}
void trivia::question1()
{
string string1;
cout<<"input your answer:"<<endl;
cin>>string1;
if(string1=="pusan")
cout<<"you are right,you can get 2 point"<<endl;
else
cout<<"you are wrong,the right answer is pusan"<<endl;
}
void trivia::question2()
{
string string2;
cin>>string2;
if(string2=="mars")
cout<<"you are right,you can get 3 point"<<endl;
else
cout<<"you are wrong,the right answer is pusan"<<endl;
}
void trivia::question3()
{
string string3;
cin>>string3;
if(string3=="yunakim")
cout<<"you are right,you can get 5 point"<<endl;
else
cout<<"you are wrong,the right answer is pusan"<<endl;
}
void trivia::question4()
{
string string4;
cin>>string4;
if(string4=="brazil")
cout<<"you are right,you can get 7 point"<<endl;
else
cout<<"you are wrong,the right answer is pusan"<<endl;
}
void trivia::question5()
{
string string5;
cin>>string5;
if(string5=="drew")
cout<<"you are right,you can get 10 point"<<endl;
else
cout<<"you are wrong,the right answer is pusan"<<endl;
}







sunsold 2009-05-18
  • 打赏
  • 举报
回复


#include <iostream>
#include <string>

using namespace std;

class trivia
{
public:
void question1();
void question2();
void question3();
void question4();
void question5();
int i;
};
void main()
{
trivia a;
int c;
string strinfo;
string ans;
do{
cout < <"输入你想回答问题的号码1-5" < <endl;
cout < <"the 1 is 2point, 2 is 3point ,3 is 5point, 4 is point,5 is 10point" < <endl;
cin>>c;
switch(c)
{
case 1:
{
cout < <"问题是" < <endl;
cout < <"Second largest city in Korea?" < <endl;
a.question1();
break;
}
case 2:
{
cout < <"问题是" < <endl;
cout < <"Fourth planet from the Sun?" < <endl;
a.question2();
break;
}
case 3:
{
cout < <"问题是" < <endl;
cout < <"National younger sister in Korea?" < <endl;
a.question3();
break;
}
case 4:
{
cout < <"问题是" < <endl;
cout < <"2002 FIFA World Cup winner?" < <endl;
a.question4();
break;
}
case 5:
{
cout < <"问题是" < <endl;
cout < <"Professor Yoo’s favorite actress?" < <endl;
a.question5();
break;
}
}
cout < <"你还想继续回答问题吗? y or n" < <endl;
cin>>ans;
}while(ans=="y");

}
void trivia::question1()
{
string string1;
cout < <"input your answer:" < <endl;
cin>>string1;
if(string1=="pusan")
cout < <"you are right,you can get 2 point" < <endl;
else
cout < <"you are wrong,the right answer is pusan" < <endl;
}
void trivia::question2()
{
string string2;
cin>>string2;
if(string2=="mars")
cout < <"you are right,you can get 3 point" < <endl;
else
cout < <"you are wrong,the right answer is pusan" < <endl;
}
void trivia::question3()
{
string string3;
cin>>string3;
if(string3=="yunakim")
cout < <"you are right,you can get 5 point" < <endl;
else
cout < <"you are wrong,the right answer is pusan" < <endl;
}
void trivia::question4()
{
string string4;
cin>>string4;
if(string4=="brazil")
cout < <"you are right,you can get 7 point" < <endl;
else
cout < <"you are wrong,the right answer is pusan" < <endl;
}
void trivia::question5()
{
string string5;
cin>>string5;
if(string5=="drew")
cout < <"you are right,you can get 10 point" < <endl;
else
cout < <"you are wrong,the right answer is pusan" < <endl;
}





65,210

社区成员

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

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