用array存储四种不同的字符串信息,并以用户答错次数作为索引值,以此方式来显示字符信息。

#include<iostream>
#include<string>
using namespace std;

const char* msg_to_usr(int par_num_tries);
void main() 
{
	int num_tries;
	cout << "please input try number:\n" << ' ';
	cin >> num_tries;
	cout << msg_to_usr( num_tries);
	int c;
	cin >> c;
}
const char* msg_to_usr(int par_num_tries)
{
	static const char* usr_msgs[ ] = 
	{
		"nice!try again!",
		"you could be better!",
		"you can do it!",
		" you need think a little more!",
		"you can try the next time!"

	};
	return usr_msgs[par_num_tries];//这个返回值很巧妙,反悔的是参数par_num_tries经过运算之后的值

 }

猜你喜欢

转载自blog.csdn.net/hwxyyf/article/details/83242619