Nov 17, 2015 01:43 PM
(This post was last modified: Nov 17, 2015 02:00 PM by MrJamieMcC.)
So this is the code
Code int caseSwitch = 1;
switch (caseSwitch)
{
case 1:
Console.WriteLine("1) Book Tickets");
break;
case 2:
Console.WriteLine("2) View Timetable");
break;
case 3:
Console.WriteLine("3) Exit");
break;
}
I want all cases to display and then the user choses one. But currently, depending on the "int caseSwitch" number thats the only switch that is displayed.
Thanks for the help :)
EDIT: This is what i mean
I want all of the options to display not just the first
Can you re-phrase what you said. It doesn't make any sense.
DO NOT DEAL WITH THIS MEMBER
Nov 17, 2015 01:53 PM
(This post was last modified: Nov 17, 2015 01:55 PM by Odus.)
Move your WriteLine statements above the entire switch block, so they'll be printed regardless. Remember sequencing and selection.
You cant do that with a switch statement.
You could do something like this.
Code Dictionary<string, Tuple<string, Action>> options = new Dictionary<string, Tuple<string, Action>>
{
{"1", new Tuple<string, Action>("Book Tickets", () => {})},
{"2", new Tuple<string, Action>("View Timetable", () => {})}
};
foreach(var o in options)
Console.WriteLine("{0}) {1}", o.Key, o.Value.Item1);
string i = Console.ReadLine();
if(options.ContainsKey(i))
options[i].Item2.Invoke();
Lotta blood to let, peace to make, give a fuk about a check
DO NOT DEAL WITH THIS MEMBER
Nov 17, 2015 01:55 PM
(This post was last modified: Nov 17, 2015 01:55 PM by Mouse❤️.)
(Nov 17, 2015 01:53 PM)BahNahNah Wrote: You cant do that with a switch statement.
You could do something like this.
Code Dictionary<string, Tuple<string, Action>> options = new Dictionary<string, Tuple<string, Action>>
{
{"1", new Tuple<string, Action>("Book Tickets", () => {})},
{"2", new Tuple<string, Action>("View Timetable", () => {})}
};
foreach(var o in options)
Console.WriteLine("{0}) {1}", o.Key, o.Value.Item1);
string i = Console.ReadLine();
if(options.ContainsKey(i))
options[i].Item2.Invoke();
Overly complicated way of doing exactly what Odus said, which is the answer to what the OP actually needs. Just move the output ...
Ive updated the post guys
DO NOT DEAL WITH THIS MEMBER
(Nov 17, 2015 01:59 PM)MrJamieMcC Wrote: Ive updated the post guys Broken image.
(Nov 17, 2015 01:59 PM)MrJamieMcC Wrote: Ive updated the post guys
Why are you even using a switch statement then 0_o.
Lotta blood to let, peace to make, give a fuk about a check
DO NOT DEAL WITH THIS MEMBER
Nov 17, 2015 02:03 PM
(This post was last modified: Nov 17, 2015 02:03 PM by Mouse❤️.)
The reason he's using a switch statement is because he wants a person to be able to enter a value, and then the program react, which is correct, but he for some reason can't read the response that this person posted:
(Nov 17, 2015 01:53 PM)Odus Wrote: Move your WriteLine statements above the entire switch block, so they'll be printed regardless. Remember sequencing and selection. The answer's right there.
Nov 17, 2015 02:07 PM
(This post was last modified: Nov 17, 2015 02:08 PM by MrJamieMcC.)
(Nov 17, 2015 02:03 PM)Mouse❤️ Wrote: The reason he's using a switch statement is because he wants a person to be able to enter a value, and then the program react, which is correct, but he for some reason can't read the response that this person posted:
The answer's right there.
You mean like this?
I still got that issue. I apologise for being idiotic, ive just started learning
(Nov 17, 2015 02:07 PM)MrJamieMcC Wrote: You mean like this? ![[Image: 389a5995ee95e3ce425435abcdc6dc8b.png]](https://i.gyazo.com/389a5995ee95e3ce425435abcdc6dc8b.png)
I still got that issue. I apologise for being idiotic, ive just started learning
Remove the conosole writelines from the switch statement.
Lotta blood to let, peace to make, give a fuk about a check
DO NOT DEAL WITH THIS MEMBER
Nov 17, 2015 02:09 PM
(This post was last modified: Nov 17, 2015 02:10 PM by Odus.)
(Nov 17, 2015 02:07 PM)MrJamieMcC Wrote: You mean like this? ![[Image: 389a5995ee95e3ce425435abcdc6dc8b.png]](https://i.gyazo.com/389a5995ee95e3ce425435abcdc6dc8b.png)
I still got that issue. I apologise for being idiotic, ive just started learning
Almost. You can remove them from the cases. Mouse saved me the hard work.
P.S You can just call WriteLine without any args to terminate the line. Or append "\n" to your string literal.
Thank you all very much. I got it to work :)
|