Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C++ (http://www.go4expert.com/forums/cpp/)
-   -   Can't stop endless loop... (http://www.go4expert.com/forums/stop-endless-loop-t21514/)

tvred 25Mar2010 03:44

Can't stop endless loop...
 
Hello, I have this problem and I can't stop it looping only 'A'...it won't print 'A' through 'Z'?...

Code:

#include<iostream>
#include<string>
using namespace std;



int main()
{
    cout << "here is a list" << endl;
    char letter = 'A';

    while (letter <= 'Z')
    {
        cout << letter << '\t' << static_cast<int>(letter) << endl;
    }

    return 0;

}


virxen 25Mar2010 05:24

Re: Can't stop endless loop...
 
letter is always equal to 'A' that's why it never stops.
you must increase its value by one inside the while.

change this
Code:

        cout << letter << '\t' << static_cast<int>(letter++) << endl;


All times are GMT +5.5. The time now is 00:56.