Calv1n
asked on
Eumeration Data Type Error
It is another term and so I am back asking more questions about assignments that are giving me problems. Just so you know this is a half completed program so ignorre the majority of the content. I have three files in my project and I am having issues with getting a enumeration data type working with a struct. I cannot get rid of these related syntax errors:
e:\School\CS 162\Assignments\Main Assignment\MainProject\myh eader.h(16 ): error C2146: syntax error : missing ';' before identifier 'category'
e:\School\CS 162\Assignments\Main Assignment\MainProject\myh eader.h(16 ): error C2501: 'foodItem::Category' : missing storage-class or type specifiers
e:\School\CS 162\Assignments\Main Assignment\MainProject\myh eader.h(16 ): error C2501: 'foodItem::category' : missing storage-class or type specifiers
Here are the copies of the file...
!!!NutritionCalc.cpp Source File:!!!
#include <iostream>
#include <iomanip>
#include "myheader.h"
using namespace std;
enum Category {
unknown = -1, meat, poultry, seafood, dairy, vegetable,
fruit, grain, sweet
};
void displayMenu();
char getCommand();
void completeTask(char command, foodItem foodItemList[], int& size);
void getfoodItem(foodItem & afoodItem);
Category category;
int main()
{
char command;
foodItem foodItemList[STORE_CAPACIT Y];
int size = 0;
displayMenu();
command = getCommand();
while(command != 'q' && command != 'Q')
{
completeTask(command, foodItemList, size);
displayMenu();
command = getCommand();
}
cout << "Thank you for using Cute Video\n" << endl;
return 0;
}
void displayMenu()
{
cout << "NutriCalc 1.0" << endl;
cout << "Created by: Brian Walsh" << endl;
cout << endl;
cout << "edit food database" << endl;
cout << "commands: a<dd>, l<ist>, d<elete> index, m<eal>, q<uit>" << endl;
cout << "------------------------- ---------- ---------- ---------- " << endl;
}
char getCommand()
{
char choice;
cout << ">";
cin >> choice;
cin.ignore(100, '\n');
return choice;
}
void completeTask(char command, foodItem foodItemList[], int& size)
{
foodItem myfoodItem;
command = tolower(command);
switch (command)
{
case 'a': getfoodItem(myfoodItem);
addfoodItem(myfoodItem, foodItemList, size);
break;
case 'l': listfoodItem(foodItemList, size);
break;
case 'd': cout << "delete is inoperable for this version." << endl;
break;
default: cout << "illegal input" << endl;
break;
}
}
void getfoodItem(foodItem& afoodItem)
{
cout << "name: ";
cin.get(afoodItem.title, MAX_LEN, '\n');
cin.ignore(100, '\n');
cout << "please enter the category(0 for A...): ";
cin >> afoodItem.category;
cin.ignore(100, '\n');
cout << "please enter the quantity: ";
cin >> afoodItem.quantity;
cin.ignore(100, '\n');
}
!!!Source File for Functions.cpp:!!!
#include <iostream>
#include <iomanip>
#include "myheader.h"
using namespace std;
void addfoodItem(const foodItem& afoodItem, foodItem foodItemList[], int& size)
{
foodItemList[size].categor y = afoodItem.category;
foodItemList[size].quantit y = afoodItem.quantity;
strcpy(foodItemList[size]. title, afoodItem.title);
size++;
}
void listfoodItem(foodItem foodItemList[], int size)
{
cout << setw(10) << "CATEGORY" << setw(30) << "TITLE"
<< setw(10) << "QUANTITY" << endl;
for(int i=0;i<size; i++)
{
cout << setw(10) << foodItemList[i].category
<< setw(30) << foodItemList[i].title
<< setw(10) << foodItemList[i].quantity << endl;
}
}
!!!Source File for myheader.h:!!!
#ifndef MYHEADER_H
#define MYHEADER_H
const int MAX_LEN = 101;
const int ACTION = 0;
const int COMEDY = 1;
const int DRAMA = 2;
const int STORE_CAPACITY = 100;
struct foodItem
{
char name[MAX_LEN]; // name of the food
Category category; // what kind of food
float calories; // calories
float carbohydrates; // grams
float fat; // grams
float cholesterol; // grams
float sodium; // grams
float protein; // grams
};
void addfoodItem(const foodItem& afoodItem, foodItem foodItemList[], int& size);
void listfoodItem(foodItem foodItemList[], int size);
#endif
THANK YOU SO MUCH AS ALLWAYS!!!
e:\School\CS 162\Assignments\Main Assignment\MainProject\myh
e:\School\CS 162\Assignments\Main Assignment\MainProject\myh
e:\School\CS 162\Assignments\Main Assignment\MainProject\myh
Here are the copies of the file...
!!!NutritionCalc.cpp Source File:!!!
#include <iostream>
#include <iomanip>
#include "myheader.h"
using namespace std;
enum Category {
unknown = -1, meat, poultry, seafood, dairy, vegetable,
fruit, grain, sweet
};
void displayMenu();
char getCommand();
void completeTask(char command, foodItem foodItemList[], int& size);
void getfoodItem(foodItem & afoodItem);
Category category;
int main()
{
char command;
foodItem foodItemList[STORE_CAPACIT
int size = 0;
displayMenu();
command = getCommand();
while(command != 'q' && command != 'Q')
{
completeTask(command, foodItemList, size);
displayMenu();
command = getCommand();
}
cout << "Thank you for using Cute Video\n" << endl;
return 0;
}
void displayMenu()
{
cout << "NutriCalc 1.0" << endl;
cout << "Created by: Brian Walsh" << endl;
cout << endl;
cout << "edit food database" << endl;
cout << "commands: a<dd>, l<ist>, d<elete> index, m<eal>, q<uit>" << endl;
cout << "-------------------------
}
char getCommand()
{
char choice;
cout << ">";
cin >> choice;
cin.ignore(100, '\n');
return choice;
}
void completeTask(char command, foodItem foodItemList[], int& size)
{
foodItem myfoodItem;
command = tolower(command);
switch (command)
{
case 'a': getfoodItem(myfoodItem);
addfoodItem(myfoodItem, foodItemList, size);
break;
case 'l': listfoodItem(foodItemList,
break;
case 'd': cout << "delete is inoperable for this version." << endl;
break;
default: cout << "illegal input" << endl;
break;
}
}
void getfoodItem(foodItem& afoodItem)
{
cout << "name: ";
cin.get(afoodItem.title, MAX_LEN, '\n');
cin.ignore(100, '\n');
cout << "please enter the category(0 for A...): ";
cin >> afoodItem.category;
cin.ignore(100, '\n');
cout << "please enter the quantity: ";
cin >> afoodItem.quantity;
cin.ignore(100, '\n');
}
!!!Source File for Functions.cpp:!!!
#include <iostream>
#include <iomanip>
#include "myheader.h"
using namespace std;
void addfoodItem(const foodItem& afoodItem, foodItem foodItemList[], int& size)
{
foodItemList[size].categor
foodItemList[size].quantit
strcpy(foodItemList[size].
size++;
}
void listfoodItem(foodItem foodItemList[], int size)
{
cout << setw(10) << "CATEGORY" << setw(30) << "TITLE"
<< setw(10) << "QUANTITY" << endl;
for(int i=0;i<size; i++)
{
cout << setw(10) << foodItemList[i].category
<< setw(30) << foodItemList[i].title
<< setw(10) << foodItemList[i].quantity << endl;
}
}
!!!Source File for myheader.h:!!!
#ifndef MYHEADER_H
#define MYHEADER_H
const int MAX_LEN = 101;
const int ACTION = 0;
const int COMEDY = 1;
const int DRAMA = 2;
const int STORE_CAPACITY = 100;
struct foodItem
{
char name[MAX_LEN]; // name of the food
Category category; // what kind of food
float calories; // calories
float carbohydrates; // grams
float fat; // grams
float cholesterol; // grams
float sodium; // grams
float protein; // grams
};
void addfoodItem(const foodItem& afoodItem, foodItem foodItemList[], int& size);
void listfoodItem(foodItem foodItemList[], int size);
#endif
THANK YOU SO MUCH AS ALLWAYS!!!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Move Category definition from cpp file to h file:
// myheader.h
#ifndef MYHEADER_H
#define MYHEADER_H
enum Category {
unknown = -1, meat, poultry, seafood, dairy, vegetable,
fruit, grain, sweet
};
const int MAX_LEN = 101;
const int ACTION = 0;
const int COMEDY = 1;
const int DRAMA = 2;
const int STORE_CAPACITY = 100;
struct foodItem
{
...
};
// myheader.h
#ifndef MYHEADER_H
#define MYHEADER_H
enum Category {
unknown = -1, meat, poultry, seafood, dairy, vegetable,
fruit, grain, sweet
};
const int MAX_LEN = 101;
const int ACTION = 0;
const int COMEDY = 1;
const int DRAMA = 2;
const int STORE_CAPACITY = 100;
struct foodItem
{
...
};
ASKER
Thank you for your help!!
Category category;
use
enum Category category;