Hiii

I just made a small Memory game with the help of many of the members of daniweb....
Now I have a screen clearing problem... The program is simple...The compiler shows random numbers,then the user inputs the number within a time limit... there is a scoring key.... but I want the the screen to be cleared before the display of next number.... after displaying the time,score, the next random number should be displayed in a clear screen... where should i put clrscr(); or should is there any other method? I also want your help in developing that game... Now the biggest problem is that cin waits and waits for the user to enter a number..... That shouldn't be allowed.... The user should MISS the chance soon once the time limit is reached...!! so i guess other input methods should be used here..But which one?... Pls help me..... It would be marvellous if you could help me

here is the code..where exactly should i add clrscr(); ??

#include <stdlib.h>

      #include <iostream.h>

      #include<conio.h>

      #include<time.h>

      #define esc q


      class game

      {

      public:

      int num,random_integer,score,start_time,last_time;

      void init_screen();

      void dispnum();

      void getnum();

      void result();

      void playgame();

      };

      void game::init_screen()

      {

      cout<<"NUMBER MEMORY GAME............. Created By Jeevan"<<endl;

      cout<<"\nIf you want to guit the game ";

      cout<<"\nanytime,Just Press Q"<<endl;

      cout<<"\n\tEnjoy!!!"<<endl;
      }

       void game::playgame()

      {

      int i=0;

      score=0;


      while(i<=50)

      {

       start_time = clock();

       last_time = clock() - start_time;

      dispnum();

      getnum();

      result();

      i++;

      }

      }


      void game::dispnum()

      {


      srand((unsigned) time(0));

      random_integer = rand();

      cout <<"\n The number is "<<random_integer<< endl;

      }

      void game::getnum()

      {

      cin>>num;

      }

      void game::result()

      {


       if((clock()-start_time)/CLOCKS_PER_SEC>9)

      {

	cout<<"\n\t\t\tIt took you too long!"<<endl;

	cout<<"\n\t\t\tIt took you "<<(clock()-start_time)/CLOCKS_PER_SEC<<" seconds!"<<endl;

	cout<<"\n\t\t\tNo points ..!"<<endl;


       }

else

      if (num==random_integer)

      {

      cout<<"\ncorrect answer"<< endl;

      score=score+1;

      cout<<"\n\t\t\t\tyour score = "<<score<<endl;

      cout<<"\n\t\t\t\tyour time "<<(clock()-start_time)/CLOCKS_PER_SEC<<" seconds!"<<endl;

      }
      else

      {

      cout<<"wrong answer! "<< endl;


      }

      }


       int main()

      {

      clrscr();

      game gam1,gam2;

      gam2.init_screen();

      gam1.playgame();

      cin.get();

      return 0;

      }

I think you should understand exactly on how these functions are called and executed and choose a spot Yourself.

And as far as the time limit is considered. You should multithread the program , I dont see anything else capable to do so.

hey...I tried.. An ts not working properly.... it isnt clearing the screen in the correct and thats why i asked you assistance... hope you would help me

There have been lots of threads here about how to clear the screen. Like this one

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.