+ 2

Alphabet: The given code declares array that holds the letters of English alphabet Task Take a no as input and output the letter

Alphabet: The given code declares array that holds the letters of English alphabet Task: Take a no as input and output the letter from array that corresponds to that index solve the given code without any syntax error with required task #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'}; } confused n can't even solve the code for task 2 which shows the output as "i"

5th Nov 2023, 7:59 AM
Syeda Rimsha Zahra Kazmi
Syeda Rimsha Zahra Kazmi - avatar
9 Réponses
+ 4
Please post your code attempt. The task involves basic steps, which were explained in the preceding lessons: - Declare a numeric variable (int type) - Take user input - Use array lookup to retrieve a value from a specific position - Output the result
5th Nov 2023, 8:26 AM
Tibor Santa
Tibor Santa - avatar
+ 2
Your code looks correct and runs without errors. I cannot access this particular task so I cannot verify what it's expecting. But usually the automated tests are not prepared to handle additional things in the output, like instructuions for the user to "Enter a number" and so on. Try to remove those from the code (or just comment them) and output only the particular letter that is requested.
5th Nov 2023, 8:35 AM
Tibor Santa
Tibor Santa - avatar
+ 2
thanks for ur time n help
5th Nov 2023, 8:42 AM
Syeda Rimsha Zahra Kazmi
Syeda Rimsha Zahra Kazmi - avatar
+ 1
here's the code but after many attempts still shows syntax error m task 1 n task 2 errors: #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 index; cout << "Enter a number between 0 and 25: "; cin >> index; if (index >= 0 && index <= 25) { cout << "The letter at index " << index << " is: " << letters[index] << endl; } else { cout << "Index out of range. Please enter a number between 0 and 25." << endl; } return 0; }
5th Nov 2023, 8:29 AM
Syeda Rimsha Zahra Kazmi
Syeda Rimsha Zahra Kazmi - avatar
+ 1
Syeda Rimsha Kazmi , The problem might be that you're printing extra unwanted text. Only print the answer. Don't print any prompting text unless the description says to, and if it does, make sure it's exactly the same text as the description. The same goes for your text introducing the answer and your out-of-range error text. Each Sololearn test case does a simple string compare between your output and the expected output that the test author entered in the test engine for that test case. It has to be an exact match. It will fail if even one character is different.
6th Nov 2023, 3:32 PM
Rain
Rain - avatar
0
here's the code but after many attempts still shows syntax error in task 1 n task 2 errors: #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 index; cout << "Enter a number between 0 and 25: "; cin >> index; if (index >= 0 && index <= 25) { cout << "The letter at index " << index << " is: " << letters[index] << endl; } else { cout << "Index out of range. Please enter a number between 0 and 25." << endl; } return 0; } still stuck in this code don't know why output shows "i" in test case 2 , first expected output n my output both are correct but in second test case its wrong don't know what happened can't solve this just still stuck in it if someone could help me n tell me to solve this code .....its in array section of "introduction to c++ " if someone who had solve this practice problem of c++ array
6th Nov 2023, 2:05 PM
Syeda Rimsha Zahra Kazmi
Syeda Rimsha Zahra Kazmi - avatar
0
How to run program
6th Nov 2023, 2:57 PM
Game Changer
Game Changer - avatar
0
Alphabet: The given code declares array that holds the letters of English alphabet Task: Take a no as input and output the letter from array that corresponds to that index solve the given code without any syntax error with required task #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'}; } confused n can't even solve the code for task 2 which shows the output as "i" so this is the code b question tried to solve but can't just getting stuck again and again if someone who had done this introduction to c++ course array part test problem plz any one could help me to solve this??!
6th Nov 2023, 3:35 PM
Syeda Rimsha Zahra Kazmi
Syeda Rimsha Zahra Kazmi - avatar
0
Rain I don't know what's wrong with this code
6th Nov 2023, 3:37 PM
Syeda Rimsha Zahra Kazmi
Syeda Rimsha Zahra Kazmi - avatar