In this program I am attempting to allow a user to input three different authors and then input three books they have written as well as the price. I am struggling with calling the functions and am not sure what to do.
#include <iostream>
#include <string>
usingnamespace std;
struct BookInfo{
string bookTitle;
double price;
};
struct Author{
string authorName;
BookInfo b[3];
};
//Above are the two structs I am using
//Function prototypes
void showInfo(Author a[], int size);
void getInfo(Author a[], int size);
int main(){
Author a[3];
a[0].authorName = "None"; a[0].b[0].bookTitle = "None"; a[0].b[0].price = 0;
a[1].authorName = "None"; a[1].b[1].bookTitle = "None"; a[1].b[1].price = 0;
a[2].authorName = "None"; a[2].b[2].bookTitle = "None"; a[2].b[2].price = 0;
//Problem comes here when I attempt to call the functions
cout << showInfo(Author a[], size);
cout << getInfo(Author a[], size);
cout << showInfo(Author a[], size);
system("Pause");
return 0;
}
void showInfo(Author a[], int size){ //Purpose is to show the information stored
cout << "Author Name: " << a[0].authorName;
cout << "Title: " << a[0].b[0].bookTitle << " Price: $" << a[0].b[0].price << "\n";
cout << "Author Name: " << a[1].authorName;
cout << "Title: " << a[1].b[1].bookTitle << " Price: $" << a[1].b[1].price << "\n";
cout << "Author Name: " << a[2].authorName;
cout << "Title: " << a[2].b[2].bookTitle << " Price: $" << a[2].b[2].price << "\n";
}
void getInfo(Author a[], int size){
/*Purpose is to get information for the two arrays
Also I would like it so if "NONE" is entered for a book title the loop will not ask for the next title
and move on to the next author.
I feel as if I should not be using a for loop here to achieve my goal */
size = 3;
Author a[3];
for(int i=0; i < size; i++){
int t=1; //Used for title number
int p=1; //Used for price number
cout << "Please enter the name of the author: ";
cin >> a[i].authorName; cout << "\n";
cout << "Enter Title " << t << ": ";
cin >> a[i].b[0].bookTitle; cout << "\n";
cout << "Enter Price " << p << ": $";
cin >> a[i].b[0].price; cout << "\n";
++t; ++p;
cout << "Enter Title " << t << ": ";
cin >> a[i].b[1].bookTitle; cout << "\n";
cout << "Enter Price " << p << ": $";
cin >> a[i].b[1].price; cout << "\n";
++t; ++p;
cout << "Enter Title " << t << ": ";
cin >> a[i].b[2].bookTitle; cout << "\n";
cout << "Enter Price " << p << ": $";
cin >> a[i].b[2].price; cout << "\n";
t = 1; p = 1; //Reset for next iteration of loop
}}
Once again, any help would be greatly appreciated!
Thank you very much! I knew it would end up being something simple like that. I'm still somewhat new to c++ so I figure the logic errors will work themselves out through experience so don't worry about that. Once again thank you!