Ok so the problem I am having is that I have an array that contains 27 characters and I need to write a function to display a specific character 0 - 25 based on a user input.
The array is a constant string:
const string ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
And the idea is that a user enters a value between 1 and 25 (int value) which then displays the cosponsoring letter in the array. I doing this by using:
cout << ALPHABET[value];
My questions are is this an appropreate way to create an array and am I able to retrieve a value from an array this way.
const string ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int main()
{
int value; //Variable defining user entered value
cout << "Please enter a number between 0-25." << endl;
cin >> value;
if (value > 25) //If statement to display "-1" if number entered is past "Z"
cout << "-1" << endl;
else
cout << ALPHABET[value];
return 0;
}
stringyou meanstd::string, you haven't really created an array. You've created an object that that allows array-like access.'A' + value?