Need help
How do i make it so i cant get into the same case twice while being in a "while" loop
43 Replies
trying to make a elevator program
can u show what you tried?
and when im on floor one (using case and whiles) i want it to say that you are already in floor one and cant get to floor one agian
show what u tried @Squirtle
where can i paste the code
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
If your code is too long, you can post to https://paste.mod.gg/ and copy the link into chat for others to see your shared code!
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
with $code ofcourse
To post C# code type the following:
```cs
// code here
```
Get an example by typing
$codegif
in chat
If your code is too long, post it to: https://paste.mod.gg/BlazeBin - yrwbavpscnqn
A tool for sharing your source code with the world!
i want it to make it so you cant get into the same floor
if you already in case 1 for example i want to type out a message that says you area already in the "bla bla" area for an example
dont know if that is possible tho with case
you need to store at what floor ur currently at to a variable
so how do i that ?
should i use bool ?
tried some things with bool
bool can't store numbers
ah
int ?
yes
should i use if ?
yes ofcourse,
i should put the if under/above row 6 correct?
check if ur not in the same floor as the floor ur trying to go to
that wouldn't work as you havent chosen the new floor yet
tried adding an int floor
and then when you are in floor 1, floor gets increased to 1
also create methods to avoid repeating codes
like
?
ah
u repeated alot of the same code in your cases
yeah true
whats only different is the welcome messages, so use a method parameter for that
true, true
floor = 1;
for (int i = 1; i < 10; i++)
{
Console.WriteLine(i + "Seconds");
Thread.Sleep(500); // stannar programkörningen
}
Console.Clear();
Console.WriteLine("Welcome to Sellingarea");
if (floor == switcher)
{
Console.WriteLine("You are already in the sellingarea");
}
tried that
but didnt work
since switcher is already 1
and yeah
hahah
u check before you enter the switch statement
how do i make it so i enter switch statement first before checking
why would u enter the switch statement before checking if u are in the same floor?
Dam thx
Really appreciate kt
It's not perfection, but hopefully it can help you to continue your own refactor and test some funny stuff
ReadInput()'s if condition if false it would return the value of the switcher (a number equal than or less than 0 or a number more than 4
never understood return
what is the function of it
you can get an idea from this example
Good point
BlazeBin - wadkvvneariv
A tool for sharing your source code with the world!
did it like this
and it works amazingly
but when i put in a letter it goes to case 0
thats the only problem i have
otherwise its perfect in my eyes
hahha
when it fails to parse switcher becomes 0 by default
you should wrap ur tryparse in a while loop
ah thx
like this