I have been playing around with this one for a while now with little success. Basically I am writing a program which is both interactive and non-interactive. I have four types of food with codes m for MEAT, f forFISH, s for SOY and e for EGGS. I have an INPUT data file with the code and weight of food items on each line. So e.g,
inFile%26gt;%26gt;code%26gt;%26gt;weight
char code;
int weight; There are about 12 lines of this file.
The interactive part involves four prompts which ask the user to enter the tax rate per kilo of MEAT, FISH, SOY and EGGS in succession. These values are then multiplied by the appropriate weight and displayed in a table. This means that for e.g, if the code is m for MEAT, then the user's input for the tax per kilo of MEAT is multiplied by the weight associated with meat(from that line of the input file).
I want to use an enum data type for MEAT, FISH, SOY and EGGS,%26amp; code the interactive part as a seperate function
C++ enumerator data type question.?
it wouldn't really make sense enumerating them differently. try:
typedef enum {EGGS = 'e', FISH = 'f', MEAT = 'm', SOY = 's'} FOOD;
int main()
{
FOOD food;
...
inFile%26gt;%26gt;food%26gt;%26gt;weight;
switch (food)
{
case MEAT: // multiply the tax per kilo by weight
....
break;
case FISH:
: ....
break;
// etc
}
....
return 0;
}
get it?
PS: I'm not too sure the enum statements are valid, if not, you can substitute them with their ASCII values, e = 101, f = 102, m = 109, s = 115
order flowers
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment