Jump to content
  • Advertisement
Sign in to follow this  
BaldPython

ScreenFill

This topic is 4604 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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] = 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
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.

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] = 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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!