C++ Alphabet | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

C++ Alphabet

I'm so lost. Can anyone help? Alphabet The given code declares an array that holds the letters of the English alphabet. Task Take a number as input and output the letter from the array that corresponds to that index. #include <iostream> using namespace std; int main() { char letters[] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'}; }

16th Oct 2023, 5:40 PM
Ryan Chu
3 Answers
+ 6
Please completely share your code otherwise we can't help you.
16th Oct 2023, 6:05 PM
Sakshi
Sakshi - avatar
+ 3
Ryan Chu declare an integer variable to hold the input value. To take input of the number from the console, you can use cin, which is the stream object that reads console input. Use that input number as the array index to retrieve the letter from the array. For example: if the user enters 2, then get the letter at index 2 of the letters array, which is 'c'. Output the letter to the console. You can use cout, the stream object that performs console output. If you are uncertain how to do the above, then it is necessary for you to review the lessons that explain variable delaration, input, output, and arrays.
17th Oct 2023, 12:58 AM
Brian
Brian - avatar
+ 2
#include <iostream> using namespace std; int main() { char letters[] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'}; Int n; cin >> n; cout << letters[n]; } You need to have and index for the array. I was having trouble with this a few minutes ago.
17th Oct 2023, 1:55 AM
Nepsus
Nepsus - avatar