Library error

My printInfo function is not printing out the information.
#include <iostream>

using namespace std;

struct book{
string title;
string author;
int publicationYear;
};

void getInfo(book);
void printInfo(book);

int main ()
{

book book1;
getInfo(book1);
printInfo(book1);



return 0;
}

void getInfo(book info)
{
cout << "What is the title of the book?" << endl;
cin >> info.title;
cout << "Who is the author of the book?" << endl;
cin >> info.author;
cout << "What is the publication year?" << endl;
cin >> info.publicationYear;
}

void printInfo(book printinfo)
{
cout << "The title is " << printinfo.title << ".\nThe author is " << printinfo.author << ".\nThe publication year is " << printinfo.publicationYear << endl;
}
Hi,

Please always use code tags http://www.cplusplus.com/articles/z13hAqkS/

The functions get a copy of the arguments, so pass the arguments by reference, and I like to put a variable name for the parameter:


1
2
void getInfo(book& TheBook);
void printInfo(book& TheBook);


Keep the same names for the same things, so far we have book1, info, printinfo - make them the same

1
2
3
4
void getInfo(book& TheBook)
cout << "What is the title of the book?" << endl;
cin >> TheBook.title;
{


1
2
void printInfo(book& TheBook)
{
Last edited on
Topic archived. No new replies allowed.