mercredi 13 mai 2015

While loop breaks, an I don't know the reason why

I was writing a code for a counter. If I give 'a' as input, it should +1 the counter and show it on the screen. But when I do it, it shows 1 on the screen and the program ends. I want it to run until and unless i give some other character as input. What's the mistake I am making?

#include <iostream>
#include <stdlib.h>
using namespace std;

int main()
{
    int Counter = 0;
    char t;

    while(true)
    {
        t = cin.get();
        if(t == 97)
        {
            Counter = Counter + 1;
        }
        else
            break;
        system("cls");
        cout << Counter;
    }
    return 0;
}

Aucun commentaire:

Enregistrer un commentaire