I\'m creating a program and need help fixing it. I\'m trying to pass an array th
ID: 3771667 • Letter: I
Question
I'm creating a program and need help fixing it. I'm trying to pass an array that uses a special struct to a function.
#include <iostream>
#include <string>
using namespace std;
const int SIZE = 3;
struct bookMaterial{ double pricing; string nameOFbook; }; double getbooks(bookMaterial books, bookMaterial SIZE);
int main(){ bookMaterial books.pricing [3] = { 22.30, 22.34, 54.23 };
getbooks(books, 3);//books is their to pass a name while the number 3 is how big the array is.
system("Pause");
return 0; }
void getbooks(bookMaterial books[], bookMaterial SIZE)
{ //In here I just display book names and the prices from above.
cout << "Stuff" << endl; }
When posing an answer, please bold it and comment (using // or /* */ symbols) so that I can see what you did.
Explanation / Answer
#include <iostream>
#include <string>
using namespace std;
const int SIZE = 3;
struct bookMaterial{
double pricing;
string nameOFbook;
};
void getbooks(bookMaterial books[], int SIZE);
//getbooks should be given an array but you gave just strucure. SIZE should be of int.
int main(){
//The way you initialized books was wrong. This is the correct way to do it.
bookMaterial books[3];
bookMaterial b;
b.pricing=22.30;
books[0]=b;
b.pricing=22.34;
books[1]=b;
b.pricing=54.23;
books[2]=b;
getbooks(books, 3);//books is their to pass a name while the number 3 is how big the array is.
return 0;
}
void getbooks(bookMaterial books[], int SIZE)
{ //In here I just display book names and the prices from above.
cout << "Stuff" << endl;
}
Please feel free to ask any further doubts.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.