This is the problem. The program works in the first run. but after you enter a key and proceed for another entry, it skips the "LAST NAME:" line and directly asks for the "FIRST NAME" line. i can't find the problem in the code so...help! >.< (skip forms and frames code)

#include <iostream.h> //header files
#include <conio.h>
#include <cstring>
#include <stdlib>
#include <fstream> //header for fstreaming of files

void form(int, int, int, int, int, int); //for form
void frame(int, int, int, int, int, int);//for frame

void main(void)
{
    char ans;
        do{
        clrscr();
        form(3,3,10,10, YELLOW,BROWN);
        gotoxy(14,4); cprintf("Girl Scouts of the Philippines Automated Registration Form");
      gotoxy(4,9); cprintf("Please enter the information needed");
      frame(2,2,79,37, LIGHTMAGENTA,WHITE); //size and color of the frame
        frame(1,1,80,38,WHITE,LIGHTMAGENTA);

      textbackground (CYAN);
      gotoxy(2,2);cprintf("");
      textbackground (CYAN);
      gotoxy(2,3);cprintf("");
      textbackground (CYAN);
      gotoxy(2,4); cprintf("");
      textbackground (CYAN);
      gotoxy(2,5);cprintf("");
      textbackground (CYAN);
      gotoxy(2,6);cprintf("");
      textbackground (CYAN);
      gotoxy(2,7);cprintf("");

      ofstream input;
      input.open("GSP.xls");
            if (input.good())
            {
         char last[60];
         char first[60];
         char middle[60];
         char address[60];
         char age[3];
         char yrsec[15];
         char bday[8];

            input.open("GSP.xls");

         textbackground (MAGENTA);
            gotoxy(4,12); cprintf("Last Name: "); cin.getline(last,60); //for enabling whitespaces
                                    input<<"Last Name: "<<last;

         gotoxy(4,14); cprintf("First Name: "); cin.getline(first, 60);
                                    input<<"First Name: "<<first;

         gotoxy(4,16); cprintf("Middle Name: "); cin.getline(middle, 60);
                                    input<<"Middle Name: "<<middle;

        gotoxy(4,18); cprintf("Address: "); cin.getline(last,60);
                                            input<<"Last Name: "<<address;

         gotoxy(4,20); cprintf("Age: ");cin>>age;
                                    input<<"Age :"<<age;

            gotoxy(4,22); cprintf("Year-Section: "); cin>>yrsec;
                                    input<<"Year-Section: "<<yrsec;

        gotoxy(4,24); cprintf("Birthday [mm/dd/yy]: "); cin>>bday;
                                    input<<"Birthday: "<<bday;
         clrscr();
         input.close();
            }

gotoxy(4,8);cprintf("Note: If you want to see the entered information go to the folder");
gotoxy(4,9);cprintf("where the program is. You can also edit the information given.");
gotoxy(4,12);cprintf("Do you wish to input more files? [y/n] "); cin>>ans;
gotoxy(40,18);cprintf("");
frame(2,2,79,37, LIGHTMAGENTA,WHITE); //size and color of the frame
frame(1,1,80,38,WHITE,LIGHTMAGENTA);
input.close();

        }while (ans=='y'||ans=='Y');

}



void form(int x1, int y1, int y2, int x2, int forecolor, int backcolor)

    {
    textcolor(forecolor); textbackground(backcolor);
    for(int k = y1; k <= y2; k++)
    for(int h = x1 ; h <= x2; h++)
    {gotoxy(h,k); cprintf("");}

    }

void frame(int x1, int y1, int x2, int y2, int color, int bgcolor)
{
    textcolor(color);
    textbackground(bgcolor);
    for(int x = x1+1; x < x2; x++)
        {
        gotoxy(x,y1); cprintf("Ä");
        gotoxy(x,y2); cprintf("Ä");

        }
    for (int y= y1+1; y < y2; y++)
        {
        gotoxy(x1,y); cprintf("³");
        gotoxy(x2,y); cprintf("³");
        }
    gotoxy(x1,y1); cprintf("Ú");
    gotoxy(x2,y1); cprintf("¿");
    gotoxy(x1,y2); cprintf("À");
    gotoxy(x2,y2); cprintf("À");
}

because after answering the "Do you want to continue" prompt you have to enter either Y or N then the <Enter> key. cin >> does not remove the Enter key so its still in the keyboard buffer. There are several ways to remove the Enter key, one of them is to call cin.ignore() after cin>>ans. Another it to just make ans a character array of two or more bytes so that cin can remove the Enter key.

Before addressing your question, I would like to point out some issues with the code as given, ones which may help understand the problem at hand. Before I do, would you mind telling us what compiler and IDE you are using? It may help us understand certain aspects of this better.

First off, your header declarations are all over the place. Your <cstring> and <fstream> declarations are correct for modern C++, but <iostream.h> is an obsolete version of the header; it should now be just <iostream>. As for <stdlib>, this is simply incorrect; the C++ header for the C standard library is <cstdlib> (note the 'c' at the beginning of the library name).

Second, while many compilers do accept void main(), strictly speaking, only int main() is correct. The reason for this is because programs do in fact return an integer value to the shell, so the declaration must reflect this.

Third, the indentation of your code is, to be blunt, a mess. You want to be both careful and consistent in how you indent you code. Now, it may be that some of this comes from using tabs in some place and space in others, something you may not have control over; but if you can, you should configure your editor so that it only uses one or the other for indenting, not both.

Fourth, if your file output, 'GSP.xls', is actually meant to generate an Excel spreadsheet (as the extension implies), then trying to write it the way you are doing isn't going to work. You would need to write an encoder which writes out Excel format, or find a library that will do it for you.

Fifth, you are repeatedly opening and closing the output file, in the default mode, which is to overwrite the existing data rather than append to it.

Sixth, you never access the stadnard namespace, either explicitly or witha using namespace std; statement.

Finally, you should know that the <conio.h> is not a standard part of the C++ language. While this isn't an error, per se, is may be the cause of some confusion.

As for the problem you are experiencing, you need to clear the input buffer before each new read. You can use cin.ignore() for this purpose - put it after each time you use cin.getline() or cin <<.

I suspect Gene is using Turbo C++ which is an ancient compiler and knows nothing about modern header files such as <fstream> and <iostram>. If that's true, then he needs to use fstream.h

As for standard namespaces, Turbo C++ doesn't require explicit declaration of it because its in the header files.

This article has been dead for over six months. Start a new discussion instead.