G
Gemma Fletcher
Hi all
I'm implementing a menu system for my assignment.
User inputs command & an if/else switch statement executes the command.
I'm just not quite sure the best way to take user input.
For eg:
L <vehicleId>
or
A <vehicleId> <Type>
So the user inputing L 123 is asking to list the vehicle who's Id is 123. Or
A 123 Ship, is asking to add a vehicle with an id of 123 and type ship.
However since all the menu commands are a mixture of just the letter (H for
help) or a command with 1 or 2 pararmeters, I can't really declare 3 input
variables and go: cin >> letter >> Id >> type, as when i run the program I
have to enter something for each variable field.
I thought maybe instead i would read in a string and then search the string
for the variables instead. However I'm not quite sure how to go about it.
I though maybe using the string class I would use the find() method, however
I'm not sure how to tell the program that once it finds (for example) the
start of a number, to read the rest of the number and save it in a temp
variable to be passed to my vehicleId variable.
Any suggestions would be appreciated,
hopefully I'm somewhat coherent - coding for hours makes my brain mushy
Thanks,
Gemma
I'm implementing a menu system for my assignment.
User inputs command & an if/else switch statement executes the command.
I'm just not quite sure the best way to take user input.
For eg:
L <vehicleId>
or
A <vehicleId> <Type>
So the user inputing L 123 is asking to list the vehicle who's Id is 123. Or
A 123 Ship, is asking to add a vehicle with an id of 123 and type ship.
However since all the menu commands are a mixture of just the letter (H for
help) or a command with 1 or 2 pararmeters, I can't really declare 3 input
variables and go: cin >> letter >> Id >> type, as when i run the program I
have to enter something for each variable field.
I thought maybe instead i would read in a string and then search the string
for the variables instead. However I'm not quite sure how to go about it.
I though maybe using the string class I would use the find() method, however
I'm not sure how to tell the program that once it finds (for example) the
start of a number, to read the rest of the number and save it in a temp
variable to be passed to my vehicleId variable.
Any suggestions would be appreciated,
hopefully I'm somewhat coherent - coding for hours makes my brain mushy
Thanks,
Gemma