ScreenFill

Started by
2 comments, last by spookycat 18 years, 5 months ago
I am making a program to fill the whole screen with an integer. But it's not working. Here's the code:


#include <iostream>
#include <stdlib.h>


enum SCREEN {
            SCREENW = 80,
            SCREENH = 24
};

void screenfill(int h=SCREENH, int w=SCREENW, int c=1){

       int array[h][w];
       for(int i=0; i <= w; i++ )
           cout << (array[h] = c) ;
       for(int J=0; J <= h; J++ )
          cout << (array[J][w] = c);

      screenfill((h-1),(w-1),c);
}


int main()
{
      system("cls");
      screenfill( (SCREENH-1) , (SCREENW-1) , 1 );
      return 0;
}


Advertisement
Thats heading for an endless loop in screenfill or at least until you run out of stack space. You need to check for going below 0 to allow the function to exit.
I changed it but still its not working ...

void screenfill(int h=SCREENH, int w=SCREENW, int c=1){       int array[h][w];       for(int i=0; i <= w; i++ )           cout << (array[h] = c) ;       for(int J=0; J <= h; J++ )          cout << (array[J][w] = c);      if( h != 0 )          screenfill((h-1),(w),c);      else if( w != 0 )          screenfill((h),(w-1),c);}
Why not just do it the simple way.
void screenfill(int h=SCREENH, int w=SCREENW, int c=1){	for ( int y = 0; y < h; y++ )	{		for ( int x = 0; x < w; x++ )		{			cout << c;		}	}}// orvoid screenfill(int h=SCREENH, int w=SCREENW, int c=1){	for ( int i = 0; i < h * w; i++ )	{		cout << c;	}}

This topic is closed to new replies.

Advertisement