I'm having a lot of trouble designing a switch statement that can take a string value I have to read from an input file and matching it up with an enum value using a switch statement so I can process the string using a function. Complicated, I know.
Here's the input example:
model<tab>Powerbook G4<tab>Apple<tab>1500
model<tab>Alienware 1000<tab>Alienware<tab>1860
update<tab>Inspiron 2500<tab>Dell<tab>2000
exit
The program reads an input file full of computer models, brands, and prices and stores them into arrays. I did that, and it works. Now I have to read another input file, like the one above, which has commands that change the values in the arrays
model: find the model and print out the brand and price
update: find the model and update it's price to the new integer listed
range: find all models within price range
exit: stop reading the command file, print a message and stop program
Here's what I have (abbreviated version)
enum Commands { MODEL, UPDATE, RANGE, EXIT }
Commands dothis // enum type for switch statement (really not sure if what to do here)
ifstream Process // input file with commands
string Execute // temporary string to hold the command to be executed
// Priming Read
getline( Process, Execute, '\t' ) // gets the command, but leaves remainder of line
switch (dothis)
case MODEL: void FindModel() // reads rest of line and searches for model and reprints
break;
case UPDATE: void UpdatePrice() // reads model and new price, updates in array, prints
break;
case RANGE: void FindInRange() // finds all models in price range and prints
break;
case EXIT: void ExitCommand() // prints "exit command found" then stops reading file
break;
getline( Process, Execute, '/t' ) // goes back for more
I won't know how many commands are in the file, but the exit command will always be last. I'm pretty sure that's how the switch statement should look, but I don't know how to take the string I read in and use it in the statement. Thanks in advance.