New line problems.

I'm very new to c++ and I've been having problems with a program I was attempting to create as practice

#include <iostream>

using namespace std;

int main(){
int x;
int y;

cout<<"ASCII chart:\n";

for(x=0;x<256;x++){
cout<<"["<<x<<"="<<(char)x<<"] ";
y=y+1;
if(y==5){
cout<<endl;
y=0;
}
}

cin.get();
}


it runs, however, in the for loop I created I attempt to create a system in which a new line is created every 5 times the loop runs. It doesn't seem to be working, in fact it seems as if that part of the code is completely overlooked every time it runs. Help would be greatly appreciated.
I'd wager that the problem is you never initialize y, so it is probably something like -2 million, so it never gets to 5.
1st initialize y to o..@firedraco's ans is right..
use
int y=0;
Thanks so much! I completely forgot.
Topic archived. No new replies allowed.