+ 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'}; }
3 Antworten
+ 6
Please completely share your code otherwise we can't help you.
+ 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.
+ 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.