Thank you, guys! I got my program to work from following your suggestions + my own trial and error. I have one last question, and it pertains to correct use or not. So, I made an extra object for my structure called "contents" so I could call that to display whatever contents i set in my function files. Is this correct usage? Is there a better or more elegant way to do this? I'll put my new working source code.
fruit_struct.h
Code:
#ifndef GUARD_fruit_struct_h
#define GUARD_fruit_struct_h
// fruit_struct.h
#include <string>
struct fruit {
std::string name;
int weight;
float price;
};
extern fruit contents, apple, banana, melon;
void fruit_f(fruit &);
void fruit_out(fruit &);
#endif
fruit_struct.cpp
Code:
// fruit_struct.cpp
#include <iostream>
#include <string>
#include "fruit_struct.h"
using std::cout; using std::endl;
fruit contents, apple, banana, melon;
void fruit_f(fruit &f)
{
apple.name = "Apple";
apple.weight = 2;
apple.price = 2.00;
banana.name = "Banana";
banana.weight = 1;
banana.price = 1.00;
melon.name = "Melon";
melon.weight = 5;
melon.price = 3.00;
banana.name = "Banana";
}
void fruit_out(fruit &f)
{
cout << "Fruit name: " << apple.name << endl;
cout << "Weight: " << apple.weight << "lbs" << endl;
cout << "$" << apple.price << endl << endl;
cout << "Fruit name: " << banana.name << endl;
cout << "Weight: " << banana.weight << "lbs" << endl;
cout << "$" << banana.price << endl << endl;
cout << "Fruit name: " << melon.name << endl;
cout << "Weight: " << melon.weight << "lbs" << endl;
cout << "$" << melon.price << endl << endl;
}
main.cpp
Code:
// main.cpp
#include "fruit_struct.h"
int main()
{
fruit_f(contents);
fruit_out(contents);
return 0;
}