#include<iostream>
#include<cstring>
#include<fstream>
#include<iomanip>

using namespace std;

void CREATELIBRARY();
//function to validate creatdate

int main()

{
	
	
	
	CREATELIBRARY();

	return 0;


}

void CREATELIBRARY()
{
	ofstream outFile;

	char creatdate[10];
	int bookno,catno,title;//[30]

	outFile.open("BOOKS.dat");

	cout<<"Enter the creation date (MM-DD-YYYY):"<<endl;
	cin.get(creatdate,20); cin.ignore(80,'\n');
	//function to validate creatdate
	cout<<creatdate<<endl;
	outFile<<creatdate;

	cout<<"Enter the number of books:"<<endl;
	cin>>bookno;
	cout<<bookno<<endl;
	outFile<<bookno<<endl<<endl;

	for(int i=0; i<bookno; i++)
	{
		cout<<"Enter the catalogue Number: "<<endl;
		cin>>catno;
		cout<<catno<<endl;
		outFile<<catno;

		cout<<"Enter the title: "<<endl;
		cin.getline(title,31); cin.ignore(80,'\n');
		cout<<title<<endl;
		outFile<<title<<endl;
	}

	outFile.close();

everything goes alright until the for loop. when the part in red is executed, everything is just printed out when it is supposed to ask and wait for the string input -title- from the user. i can't figure out what the problem is. would greatly appreciate any help, thanks!

After entering an integer and pressing <Enter> key the Enter key '\n' is still in the keyboard, cin does not remove it. You need to call a function to flush it -- such as cin.ignore() -- after line 47.

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.