Question
need help c++ not compiling. .cpp file #include #include #include #includeFood.h using namespace std; class Nutrition{ private: string name; double Calories; double Fat; double Sugars;
need help c++ not compiling.
.cpp file
#include
class Nutrition{ private: string name; double Calories; double Fat; double Sugars; double Protein; double Sodium; public: Nutrition(string n, double c, double f, double s, double p, double S) : name(n), Calories(c), Fat(f),Sugars(s), Protein(p),Sodium(S){} Nutrition(string type, double calories, double fat, double sugar,double protein, double sodium){ name = type; Calories = calories; Fat = fat; Sugars = sugar; Protein = protein; Sodium = sodium; } void setName(string type){ name = type; } void setCalories(double calories){ Calories = calories; } void setFat(double fat){ Fat = fat; } void setSugars(double sugar){ Sugars = sugar; } void setProtein(double protein){ Protein = protein; } void setSodium(double sodium){ Sodium = sodium; } string getName(){ return name; } double getCalories(){ return Calories; } double getFat(){ return Fat; } double getSugars(){ return Sugars; } double getProtein(){ return Protein; } double getSodium(){ return Sodium; } };
.h file
#ifndef FOOD_H #define FOOD_H class Nutrition { private: string name; double Calories; double Fat; double Sugars; double Protein; double Sodium; public: Nutrition(string n, double c, double f, double s, double p, double S) : name(n), Calories(c), Fat(f), Sugars(s), Protein(p), Sodium(S) {} Nutrition(string type, double calories, double fat, double sugar, double protein, double sodium) { name = type; Calories = calories; Fat = fat; Sugars = sugar; Protein = protein; Sodium = sodium; } void setName(string type) { name = type; } void setCalories(double calories) { Calories = calories; } void setFat(double fat) { Fat = fat; } void setSugars(double sugar) { Sugars = sugar; } void setProtein(double protein) { Protein = protein; } void setSodium(double sodium) { Sodium = sodium; } string getName() { return name; } double getCalories() { return Calories; } double getFat() { return Fat; } double getSugars() { return Sugars; } double getProtein() { return Protein; } double getSodium() { return Sodium; } Nutrition operator+(Nutrition &F) { Nutrition temp; temp.Calories = Calories + F.getCalories(); temp.Fat = Fat + F.getFat(); temp.Sugars = Sugars + F.getSugars(); temp.Protein = Protein + F.getProtein(); temp.Sodium = Sodium + F.getSodium(); return temp; } }; void display(Nutrition text) { cout << "Your total intake is" << endl; cout << " Calories consumed:" << text.getCalories() << endl; cout << " Total Sugar consumed:" << text.getSugars() << endl; cout << " Protein consumed:" << text.getProtein() << endl; cout << " Sodium consumed:" << text.getSodium() << endl; cout << " Fat consumed:" << text.getFat() << endl; } const int MAX = 11; vector
Items.push_back(I1); Items.push_back(I2); Items.push_back(I3); Items.push_back(I4); Items.push_back(I5); Items.push_back(I6); Items.push_back(I7); Items.push_back(I8); Items.push_back(I9); Items.push_back(I10); Items.push_back(I11);
int main() { Nutrition Items[MAX]; int size = 0; int choice = -1; Nutrition selected; int selectedItemCount = 0; while (choice != size + 2) { cout << "Choose a nutrition item to select:" << endl; for (int i = 0; i < size; i++) { cout << i + 1 << ": " << Items[i].getName() << endl; } cout << size + 2 << ": Finished" << endl; cin >> choice; if (choice == size + 1) { size = addItem(Items, size); } else if (choice > 0 && choice < size + 1) { selected = selected + Items[choice - 1]; selectedItemCount++; } else if (choice < 1 || choice > size + 2) { cout << "Invalid input, please try again." << endl; } } if (selectedItemCount > 0) { print(selected); cout << endl; checkExcess(selected); } return 0; }
The program should prompt the user to choose a food item from a list of options. The program should continue looping until the user enters the option to stop. At that time the total nutritional value of all of the food items selected should be combined and displayed.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started