KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I have a structured a data type called bookStruct and books is the name of the variable associated with the bookStruct data type. book[10] is the array that is 10 characters long and has 4 characters of data, meaning book[0] to book [3] have datas in them when the rest are empty (o values). Now I want to print the datas that are availabe already in the array and not print the ones that are empty otherwise 0. I tried the below code, with no luck.What am I doing wrong here? for (int i=0;i<MAX_BOOKS && books[i]!='\0';i++) { cout << "Book Title: " << books[i].bookTitle << endl; cout << "Total Pages: " << books[i].bookPageN << endl; cout << "Book Review: " << books[i].bookReview << endl; cout << "Book Price: " << books[i].bookPrice<< "\n\n" << endl; } here is the declaration for book struct struct bookStruct { string bookTitle; int bookPageN; int bookReview; float bookPrice; }; bookStruct books[10];
Tags (comma-separated)
Save Edits
Cancel