Looks like a great boardI will be honest here. I am 31 years old and I have recently decided to take some classes, to see what may spark some interest. Well right now I need some help!
I would like to see if any one can help me figure out this mess I have made.
Now what I am aiming for is displaying the total amount of calories for entrees that the user will input (for all 21 meals). But somewhere I have missed a few things.Code:#include<iostream> #include<cstring> using namespace std; class Meal { friend ostream& operator<<(ostream& out, const Meal &aMeal); friend istream& operator<<(istream& in, Meal &aMeal); public: char entree[20]; int calorie; Meal(char ent[]); //constructor int operator + (Meal &meals); //overload operator + }; Meal::Meal(char ent[]) { strcpy(entree, ent); calorie = calorie; }; int Meal::operator + (Meal &meals) { int cals; cals = calorie + meals.calorie; return (cals); }; ostream& operator<<(ostream& out, const Meal &aMeal) { out<<"The total calories for all of the meals is: "<<endl; return(out); }; istream& operator<<(istream& in, Meal &aMeal) { cout<<"Enter the entree: "; in>>aMeal.entree; cout<<"Enter the amount of calories: "; in>>aMeal.calorie; return(in); }; int main(void) { Meal meals[21]; for(int i = 0; i < 21; i++) meals[i]; cin>>i; cout<<i; return 0; };
An overload extraction operator is needed to prompt the user for an entree' name and calorie count for a meal.
Also need the statement total = breakfast + lunch + dinner; in the program... but is it possible to get this code to run without that statement?
Thanks in advance for any replys.![]()



LinkBack URL
About LinkBacks
I will be honest here. I am 31 years old and I have recently decided to take some classes, to see what may spark some interest. Well right now I need some help! 


