I am working on a program that uses an array called Game that can store 26 characters. It asks the user to to enter a single letter and a number between 1 and 26. It then places the letter they entered into the position in the array referenced by the number they entered. I used a while loop to see if they wanted to play again. It then displayed the contents of the array with a for loop.
The problem that i am having is that when the program executes it enters the letters in the correct spot but it also puts some different characters in other spots that i do not want. i only want the letters in the assigned spot. Can somone look at my code and let me know where my code is incorrect and give me some guidence.
Thank you so much
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
//Declarations
char Game[26];
char letter;
char Repeat = 'Y';
int number;
while (Repeat == 'Y' || Repeat == 'y'){
//Input
cout << "Please enter a letter: ";
cin >> letter;
cout << "Please enter a number between 1 and 26: ";
cin >> number;
while (number <= 0 || number >= 27){
cout << "Invalid Entry." << endl;
cout << "Please enter a number between 1 and 26: ";
cin >> number;
}
Game [number] = letter;
cout << "Do you want to play again? (Y or N): ";
cin >> Repeat;
cout << endl;
}
cout << "Game Over!" << endl << endl;
//Process
cout << "The array contains:" << endl;
for (int x=1; x<=26; x++)
cout << "Element at index " << x << " is " << Game[x] << endl;
//Output
system ("pause");
return 0;
}