My assignment is rather lengthy and kind of confusing to explain. I have to write a code to sort of create a book store. It needs to create a struct named book and have the user enter the book number, price, and copies sold. There must be at least 5 entries and then print them as a chart in this form...
Book number Book Price Copies Sold Total Sales
7 $15.95 15 $239.25

I also have to declare a variable "inventory" that is an array of books.

Then have to write a function "intro()" that creates an opening menu (switch statement) that prints the store's name along with a list of options available to the user. The options are: List all of the information in the inventory, Take delivery of books to add to the inventory
or Quit the program and sace the inventory to inBooks.txt file

The completed menu should look like this:
L List all of the information in the inventory
D Take delivery of books to add to the inventory
Q Quit the program and sace the inventory to inBooks.txt file

I have a lot done, but this is my first class every in C++ and im not very good with writing code so it may very well be poorly done and incorrect. I think im mostly confused on whether or not i placed everything in the correct spot. Also, as it is right now, there are no error messages coming up however it does say this.....
in function 'main':
[Linker error] undefined reference to `Delivery(book*, int&)'
Id returned 1 exit status

Here is what i have so far:

#include <iostream>
#include <fstream>
using namespace std;

struct book
{
int book_number, copies_sold;
double book_price;
};//end struct

void Delivery(book inventory[], int& size);

int main()
{
book inventory[100];
int size=0, num, book_number, copies_sold;
double book_price, calc_total_sales;
char option;

ifstream in;
in>>num;
ofstream out;
out<<num;

in.open("Bookstore.txt");
if (!in.fail())//didnt fail=file is open
{//read the file
while (in>>inventory[size].book_number)
{in>>inventory[size].copies_sold;
in>>inventory[size].book_price;
size++;
}//end while
in.close();


{
     int add;
     cout<<"How many books do you want to add?";
     cin>>add;
     
for (int i=size;i<add;i++)

{
    
    
cout<<"What is the book number? ";
cin>>inventory[i].book_number;
cout<<"How much is the book? $ ";
cin>>inventory[i].book_price;
cout<<"How many copies were sold? ";
cin>>inventory[i].copies_sold;
}
size=size+add;
}
calc_total_sales=book_price*copies_sold;
cout<<"Book Number\tBook Price\tcopies sold\tTotal sales\n";
cout<<"_________________________________________________________\n";
{cout<<book_number<<"\t"<<"\t"<<book_price<<"\t"<<"\t"<<copies_sold<<"\t"<<"\t"<<calc_total_sales<<"\n";
}
{
bool valid=true;
while (valid==true)

switch (option)
{
       case 'L': 
            cout<<"List the table\n";
       break;
       case 'D': 
            cout<<"Take \n";
       Delivery(inventory, size); //call statement
       break;
       case 'Q': 
            cout<<"Quit\n";
       valid==false;//exit the while loop
       }
       }
       }
return 0;
}

Im sorry if my explanation of my task is rather confusing, but if anyone could help i would greatly appreciate it! Thank you so much!!

>>Linker error] undefined reference to `Delivery(book*, int&)'
That error message means you failed to write the function named Delivery.

Will I write it for you? Answer: no. But give a try and come back with any questions you may have.

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