while "letter" is less than Z, which it will be at least the first time, because you've just set it to 'A'. what about the second time the while loop runs?
Next time the loop goes on, It is still A. So A is still less than Z... This goes on and on, because you never change the variable "letter".
A for loop:
Code:
for(int i = 0; i < 10; )
{
cout << i;//Endless loop, goes on forever, because i is ALWAYS less then 10.
}
Code:
for (int i = 0; i < 10;)
{
cout << i;
i = i + 1; // We increase 1 to i, every time, so variable "i" will sooner or later be greater than 10!
}
Same goes for your while loop, with char data type.
Change the "letter" inside the loop...
Can you manage to change a while loop with a variable of type char, now I've explained how you do it with for-loops and int variables?
PS: You want to print out a list of all characters in the alphabet?
I would have done it like this:
Code:
char letters[26];
letters[0] = 'A';
for(int i=0; i < 26; i++)
{
cout << letters[i] << " ";
letters[i+1] = letters[i] + 1;
}
After this is ran, letters[0] = A, letters[1] = B, letters[2] = C, letters[3] = D...so on. If you want to store the characters, as in; if you dont need the characters for anything later on, I would not use an array here ofc... JUst printed the variable letter + i...