#include<iostream>
#include<string>
using namespace std;
struct one
{
	char name_book[80];
	char name_author[80];
	int no_of_books;
}one1[500];

int insert()
{
	int i,j;
	cout<<"Enter the No. of Books you want to enter : ";
	cin>>i;
	cout<<endl;
	for(j=0;j<i;j++)
	{
		cout<<"Enter the name of book "<<j+1<<" : ";
		cin>>one1[j].name_book;
		cout<<"Enter the name of the Author of the book "<<j+1<<" : ";
		cin>>one1[j].name_author;
		cout<<"Enter the number of books in this title "<<" : ";
		cin>>one1[j].no_of_books;
		cout<<"\n";
	}
	for(j=0;j<i;j++)
	{
		cout<<"The name of book "<<j+1<<" is : ";
		cout<<one1[j].name_book;
		cout<<endl;
		cout<<"The author's name for book "<<j+1<<" is : ";
		cout<<one1[j].name_author;
		cout<<endl;
		cout<<"The number of books in this title are "<<"book is : ";
		cout<<one1[j].no_of_books;
		cout<<endl;

	}
	return 0;
}

void main()
{
	insert();
}

The problem is in line 20 i have to use cin and am not able to use cin.getline
but cin.getline should be used as cin breaks when it reads a space that's why cin.getline should be used but when i use cin.getline the entry for teh 1st book is not taken but it runs normally for the entry of second book plz help!!

tux4life commented: if( post == 1 && code_tags ) rep++; :P +8
Sky Diploma commented: Though you have used code-tags. Void main is very bad! +0

You'll have to describe your problem clearer then this.
- What is your input ?
- What is your output?
- What ouput were you expecting?

And what happens when the user enters a number bigger then 500?

when i run this prigram using cin.getline(one1[j].name_book,80);
in line 20

the output is

Enter the No. of Books you want to enter : 2

Enter the name of book 1 : Enter the name of the Author of the book 1 : qwerty
Enter the number of books in this title : 5

Enter the name of book 2 : Enter the name of the Author of the book 2 : qwerty
Enter the number of books in this title : 50

The name of book 1 is :
The author's name for book 1 is : qwerty
The number of books in this title are book is : 5
The name of book 2 is :
The author's name for book 2 is : qwerty
The number of books in this title are book is : 50
Press any key to continue


see the program doesn't take the input of name of book but it does when i use cin but i want to use cin.getline even gets doesn't work

After entering an integer you have to flush the '\n' <Enter key> from the keyboard buffer. The easiest way to do that is cin.ignore(1000,'\n'); . Read this thread for more details.

You have to clear the input buffer. You could use something like: cin.ignore(80,'\n'); [edit]
Whoops, I was too slow and AD already posted the answer ;)

Thankyou very much for solving my querry
Ancient Dragon
&
niek_e

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.