#include <iostream>
#include <vector>
using namespace std;
struct CD_TYPE
{
string title, artist;
int year;
double cost;
} ;
void printData(struct <CD_TYPE> &collection[]);
int main()
{
vector <CD_TYPE> collection(2);
collection[0].title ="That's All Folks";
collection[0].artist = "Porky Pig";
collection[0].year = 2000;
collection[0].cost = 12.95;
collection[1].title ="I Thought I Saw A Putty Cat";
collection[1].artist = "Tweety Bird";
collection[1].year = 2001;
collection[1].cost = 14.50;
printData(collection);
}
void printData(struct <CD_TYPE> &collection[])
{
for (int i = 0; i < 5; i++) {
cout<<collection[i].title<<"\n"<< collection[i].artist<<"\n"<<collection[i].year<<"\n"<<collection[i].cost<<endl;
}
}
What I have tried:
I have tried to resolve this issue by removing the function and the code then works, but I need this code to have a function, but for some reason, there is an error with my prototyping or something. Help would be greatly appreciated as this is a summative assignment, Thank you.
My Explanation
For some reason, my code is not working and there are 5 errors coming that are all related to the
functions of my code. I believe I did no properly pass the function from the main or that I did not
prototype them correctly.
Errors:
main.cpp:11:16: error: variable or field ‘printData’ declared void
void printData(struct <cd_type> &collection[]);
^ main.cpp:11:16: error: expected primary-expression before ‘struct’
main.cpp: In function ‘int main()’:
main.cpp:24:25: error: ‘printData’ was not declared in this scope
printData(collection);
^ main.cpp: At global scope:
main.cpp:27:16: error: variable or field ‘printData’ declared void
void printData(struct <cd_type> &collection[])
^ main.cpp:27:16: error: expected primary-expression before ‘struct’