printing arrays with a void fuction

I'm supposed to input values into an class array but the loop is in the function call.
this is what I'm currently doing.

1
2
3
4
5
6
7
8
9
10
void bookType::setBookInfo(string title, string ISBN, string Publisher, int PublishYear, string auth[4], double cost, int copies, int authorCount) {
	book.title = title;
	book.ISBN = ISBN;
	book.Publisher = Publisher;
	book.PublishYear = PublishYear;
	for (int i = 0; i < authorCount; i++)
		book.auth[i] = auth[i];
	book.price = cost;
	book.copies = copies;
	book.authorCount = authorCount;
what loop is in what function call, and where did you want it instead?
What you have looks ok, assuming a lot of things are correct elsewhere that we can't see (which is fine, if they work etc).
what is a class array? bookType blah[100]; <--- like this?
if you have an array of your booktypes then where that lives, probably in main, you just need a loop, in crude pseudo code, something like:
while(user keeps typing things? for a fixed number? something)
{
cin >> localvariables like title, isbn, etc.
blah[index++].setbookinfo(all the stuff);
}

or, slightly more mature/clean:
bookType tmp;
cin >> tmp.title; //do you have getters and setters for these fields??
cin >> tmp.ISBN;
... //etc
blah[index++] = tmp; //make an assignment operator to do this work!

> title: printing arrays
guessing cout

> description: I'm supposed to input values
guessing cin

> the loop is in the function call.
¿?

> function: setBookInfo()
¿so what do you want to do?

> this is what I'm currently doing.
¿and the problem is?


I see that bookType has a book object of unkown type...
Topic archived. No new replies allowed.