#include<iostream>
#include<cstring>
using namespace std;
const string qualify[4] =
{
"10,000-meter race.\n",
"mud tug-of-war.\n",
"master canoe jousting.\n",
"pie-throwing festival.\n",
};
int main()
{
int age;
cout << "Enter your age in years: ";
cin >> age;
int index;
if (age > 17 && age < 35)
index = 0;
else if (age >= 35 && age < 50)
index = 1;
else if (age >= 50 && age < 60)
index = 2;
else
index = 3;
cout << "You qualify for the " << qualify[index];
return 0;
#include<cstring>
using namespace std;
const string qualify[4] =
{
"10,000-meter race.\n",
"mud tug-of-war.\n",
"master canoe jousting.\n",
"pie-throwing festival.\n",
};
int main()
{
int age;
cout << "Enter your age in years: ";
cin >> age;
int index;
if (age > 17 && age < 35)
index = 0;
else if (age >= 35 && age < 50)
index = 1;
else if (age >= 50 && age < 60)
index = 2;
else
index = 3;
cout << "You qualify for the " << qualify[index];
return 0;
}
#include<iostream>
const char*qualify[4] =
{
"10,000-meter race.\n",
"mud tug-of-war.\n",
"master canoe jousting.\n",
"pie-throwing festival.\n",
};
int main()
{
using namespace std;
int age;
cout << "Enter your age in years: ";
cin >> age;
int index;
if (age > 17 && age < 35)
index = 0;
else if (age >= 35 && age < 50)
index = 1;
else if (age >= 50 && age < 60)
index = 2;
else
index = 3;
cout << "You qualify for the " << qualify[index];
return 0;
}
下面的有char型指针的方式运用数组字符串和&&选择范围是重要知识点,上面用了string型的数组虽然可以存放,但不能使用。