Can someone help me? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Can someone help me?

#include <iostream> using namespace std; int main() { char arr[] = {'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'}; char letters[26]; // Declare an array for letters with the same size as 'arr'. // Copy the values from 'arr' to 'letters'. for (int i = 0; i < 26; i++) { letters[i] = arr[i]; } cout << letters[1]; // This will print the second letter 'b' (index 1) from the 'letters' array. } this is what I have so far. Task: Take a number as input and output the letter from the array that corresponds to that index.

17th Oct 2023, 1:14 AM
Ryan Chu
3 Answers
0
You don't know how do enter user data?
17th Oct 2023, 2:33 AM
Solo
Solo - avatar
0
Building on what you have int index; cin >> index; index %= 26; cout << letter [index];
17th Oct 2023, 5:53 AM
Raul Ramirez
Raul Ramirez - avatar
0
Just do cin>>index, declare int index first of course and then you just need to do cout << letters[index].
17th Oct 2023, 8:01 PM
Werg Serium
Werg Serium - avatar