Ok,so I have a struct and I need to create a function that increases the amount of a book.After calling the function for each book ,I will call printBooks which I can do just fine.I know it’s a very simple program but I just couldn’t do it so any help is appreciated
#include <iostream>
using namespace std;
#define BOOKS 3
struct Book
{
string title;
string isbn;
int amount;
} books [BOOKS];
void printBooks(Book b);
void addAmount(Book &book,int amount);
int main()
{
int i;
for(int i = 0;i < BOOKS; i++)
{
cout << "Enter isbn : ";
cin >> books[i].isbn;
cout << "Enter title : ";
cin >> books[i].title;
cout << "Enter amount : ";
cin >> books[i].amount;
}
cout << "\nThe number of books after adding amount by one :\n";
for(i = 0;i < BOOKS; i++)
{
addAmount(); // intentionally left blank.don't know what to put
printBooks(books[i]);
}
return 0;
}
void printBooks(Book b)
{
cout << b.isbn << endl;
cout << b.title << endl;
cout << b.amount << endl;
}
void addAmount(Book &book,int amount)
{
book.amount++;
}
You’re calling
addAmount();without parameters. You probably meanAlso consider changing the
printBookssignature toor, even better, making it a member function.