-
Notifications
You must be signed in to change notification settings - Fork 72
Expand file tree
/
Copy pathEx5_11.cpp
More file actions
28 lines (25 loc) · 810 Bytes
/
Ex5_11.cpp
File metadata and controls
28 lines (25 loc) · 810 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// Working with strings in an array
import <iostream>;
import <array>; // for std::size()
int main()
{
const size_t max_length{ 80 }; // Maximum string length (including \0)
char stars[][max_length]{
"Fatty Arbuckle", "Clara Bow",
"Lassie", "Slim Pickens",
"Boris Karloff", "Mae West",
"Oliver Hardy", "Greta Garbo"
};
size_t choice{};
std::cout << "Pick a lucky star! Enter a number between 1 and "
<< std::size(stars) << ": ";
std::cin >> choice;
if (choice >= 1 && choice <= std::size(stars))
{
std::cout << "Your lucky star is " << stars[choice - 1] << std::endl;
}
else
{
std::cout << "Sorry, you haven't got a lucky star." << std::endl;
}
}