I want to simply type in the information and have it recorded into the appopriate value
Enums aren't variables, they are constants, so you can't read input into an enum. Enums just make your code more readable, they don't actually do anything logic wise. In fact, I suggest you forget about them completely since they seem to be a bright light blinding you from seeing what you need to do. After you work out the logic of your program, and finish writing it so that it works correctly, then if you have time, and you want to make your code more readable, you can go back and add some enums where appropriate. At this point in your C++ learning, don't dwell on enums--they are syntactic sugar.
For instance, this might be your main() file:
Code:
#include <iostream>
#include "fish.h"
using namespace std;
void display_message(int fishType);
int main()
{
int input;
cout<<"Enter an int designating the the type of fish you caught\n";
cout<<"(bass=0, trout=1, carp=2): ";
cin>>input;
display_message(input);
return 0;
}
and here is "fish.h":
Code:
//fish.h
#ifndef __FISH_H__
#define __FISH_H__
#include <iostream>
using namespace std;
void display_message(int fishType)
{
switch (fishType)
{
case 0:
cout<<"Last year there was a blight on those fish and 4,000 were killed."<<endl;
break;
case 1:
cout<<"According to statistics, that is the most popular fish to eat."<<endl;
break;
case 2:
cout<<"In 2004, 40,000 anglers ranked that fish as one of the\n";
cout<<"best fighters pound for pound."<<endl;
break;
default:
cout<<"I've never caught any of those."<<endl;
}
}
#endif //__FISH_H__
In the file "fish.h", it's not exactly clear what 0, 1, and 2 mean. In fact, as you are programming that, you may even forget what they mean and get the messages mixed up. So, you might create an enum:
Code:
//fish.h
#ifndef __FISH_H__
#define __FISH_H__
#include <iostream>
using namespace std;
void display_message(int fishType)
{
enum {bass, trout, carp}; //anonymous enum
switch (fishType)
{
case bass:
cout<<"Last year there was a blight on those fish and 4,000 were killed."<<endl;
break;
case trout:
cout<<"According to statistics, that is the most popular fish to eat."<<endl;
break;
case carp:
cout<<"In 2004, 40,000 anglers ranked that fish as one of the\n";
cout<<"best fighters pound for pound."<<endl;
break;
default:
cout<<"I've never caught any of those."<<endl;
}
}
#endif //__FISH_H__
Now, it's clearer what's going on in "fish.h", and it may be easier for you as a programmer to keep from getting the messages in the wrong cases. Note, that the first "fish.h" worked perfectly fine in the program--it just wasn't that readable--and the only thing adding an enum did was change some numbers to words.