Whats wrong with this code in C? Using Dev-C++ 4.9.9.2

Lonkut

..--""--..
Joined
Jul 13, 2004
Messages
862
Location
......
It compiles fine but when I run, table appears and then disappears in a second. Why?
#include <stdio.h>

int main()
{
int table_size = 12;
int row = 0;
int col = 0;

for(col=0 ; col<=table_size ; col++){
printf(" %4d", col);
}
printf("\n");
for(col=0 ; col<=table_size ; col++){
printf("_____");
}

for(row = 0 ; row<=table_size ; row++){
printf("\n");
for(col = 0 ; col<=table_size ; col++) {
if(row == 0) {
if(col == 0){
printf(" ");
}else{
printf("|%4d", col);
}
}else{
if(col == 0){
printf("%4d", row);
}else{
printf("|%4d", row*col);
}
}
}
}
printf("\n");
}
 
It's working like a console program is supposed to. Either run it via the command prompte or add this to the header to make it stay open:

Code:
#include <iostream.h>
#include <conio.h>

And this to the end of main():

Code:
cout<<endl<<"Press any key to continue";

getch();

Not sure about Dev-C++, but some IDEs (old Borland) can compile 16-bit easywin applications which stay open until you close them.
 
Back
Top Bottom