Topic: Help! Please.. (Contains my source) cin>> getting skipped


Author: bnapier@comp..uark.edu (Brian H. Napier)
Date: 31 Oct 1994 19:31:55 GMT
Raw View
Hello.  I would like some help if possible.  I am trying to make
this simple little menu program.  I have a problem.  Program starts...
It displays my PICT resource perfectly. Then it goes to my menu.cpp section
and starts looping.  The program skip my cin>> statement.  When I comment
out the Titlescreen the program works fine.  So, I must have some
line missing in the Titlescreen program. Some buffer thingy?
I would very very much appresciate it if someone could help me with this.


#include <iostream.h>
#include <console.h>

... prototypes deleted


void MenuDriver()
{
     const char
         Menu[] = "\n\t\t\tMain Menu"     //Character Array used for Menu Text
                  "\v\n\tA  Perimeter of a Square"
                  "\n\n\tB  Area of a Rectangle"
                  "\n\n\tC  Volume of a Rectangle"
                  "\n\n\tD  Volume of a Sphere"
                  "\n\n\tE  Volume of a Pyramid"
                  "\n\n\tQ  to Quit program";


           char Calculation;            // selection variable

     do
     {
          ClearScreen();
          cout<<Menu;                   //display menu
          cgotoxy(9,23,stdout);        //reposition cursor to bottom left of screen(+9)
          cout<<"Please enter your choice: ";
          cin>>Calculation;             // receive choice
 *** This cin statement gets skipped...
        switch(Calculation)
        {
             case'a':case'A':  PerimeterSquare();break;
             case'b':case'B':  AreaRectangle();break;
             case'c':case'C':  VolumeRectangle();break;
             case'd':case'D':  VolumeSphere();break;
             case'e':case'E':  VolumePyramid();break;
             case'q':case'Q': break;     //allow loop drop out
           default:
            {

                cout<<"\n\nInvalid Choice... ";   // information to user
                GetAnyKey();

            }  //default
         }  //switch
      }  //do

     while ((Calculation!='q') && (Calculation!='Q'));

  } // MenuDriver

+++++++++++++++++    Next file.........
#include <time.h>
#include <quickdraw.h>


void Pause();
void Display();
void InitToolbox(void);
void MYNewWindow(void);

void TitleScreen()
{
 InitToolbox();
    MYNewWindow();
    Display();
 Pause();

}

void InitToolbox()
{
 InitGraf((Ptr) &qd.thePort);
 InitFonts();
 InitWindows();
 InitMenus();
 FlushEvents(everyEvent,0);
 TEInit();
 InitDialogs(0L);
 InitCursor();
}




void Display()
{



       PicHandle     myPicHandle;
       Rect          r;

       myPicHandle=GetPicture(128);
       r=(**myPicHandle).picFrame;
       OffsetRect(&r,-86,-24);
       DrawPicture(myPicHandle,&r);

}

void MYNewWindow()
{
  WindowPtr theWindow;
 theWindow = GetNewCWindow(128,nil,(WindowPtr)-1L);
 ShowWindow(theWindow);
 SetPort(theWindow);
}


void Pause()
{
   int Start,End;
   Start=clock();
   End=clock();
   while (300 > (End-Start))
     End=clock();
}