Sign in to follow this  
BaldPython

ScreenFill

Recommended Posts

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][i] = 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;
}


Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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][i] = 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);
}


Share this post


Link to post
Share on other sites
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;
}
}
}

// or

void screenfill(int h=SCREENH, int w=SCREENW, int c=1)
{
for ( int i = 0; i < h * w; i++ )
{
cout << c;
}
}

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this