✅ Spent almost an hour trying to independently get this right and it’s not clicking for me.
no flame pls


114 Replies
and what have you tried?
I tried a while loop
while(floors >=0);
Console.WriteLine(floors++);
I just don’t know how to get it in increments of 5

This is the furthest I’ve gotten
You need to be banned
Guess why
Bro I’m trying
It’s hard man
You still using convert after what I told ya
No the app did that for me
The app gives you a foundation to build from I didn’t code that.
if you have nothing constructive to say to him then just dont.
Every person learns in a different way and pace, be mindful pls.
You missed the plot my guy I was kidding
there is no plot, just dont say thing u shouldnt in help threads.
I was referring to his previous thread
u can keep those on #chat
he helped me earlier
Salmon just a chill guy
I know he is, but help threads are meant to be a more serious place instead of throwing punches anyway... on to your question
Is the while loop the wrong approach ?
I have an idea of what to do just don’t know how
you can use the remainder operator
Do you see a pattern in the question?
while floors < 0
Floors + 5
no the while loop is fine, I meant as the way to identify the floors
more like currentFloor < floors
Question says on every 5th floor
so you need to determine if the floor is divisible by 5 , now it's on you how to figure that
cause floors will never be below 0 unless you have bad input
with that change that code should work
well you would of course increment currentFloor instead of floors
Hmm okay
I haven’t exactly learned to use division in code like he suggested but I get the idea
basically if N divided by 5 is 0 it means its divisible by 5 so it means we are in one of those floors
and that's what the remainder operator does
I assume you have learned about if else conditions?
Yes
so essentially u would do
where your condition is the evaluation of the remainder
I know its more code but I also suggest you to use the bracers to define your code blocks so u dont accidently run into problems
i.e.:
and no mistake things like
where the 2nd console.writeline does not belong to the loop.
I’ve had that issue before and was not understanding why.
It’s easy to use the Microsoft visual script
This platform on the phone is horrible
you mean Visual Studio yes its a lot easier

Holy shit I’m getting some where
It just needs to be capped
Input was 9 and output was 5 and 10
yep that is where u will need the condition and how to identify the floors
Can you explain the condition again
Sorry I didn’t understand
In this method, you actually don't need to check remainder
Could I use an if break ?
If (floors > res)
break;
break will, break you out of loop, switches etc
so if u break it will exit the loop
That’s what I want though right
Because input given was 9 and I got an output of 5 and 10
It needs to break before I outputting 10
yes, only increment if it's in the bounds
Now it says my code is wrong

It won’t run
because you put the { before the loop
You missed the brackets around while as Leo said
the code is
Oh I see
using System;
public class Program
{
public static void Main(string[] args)
{
int i = 0;
Console.WriteLine ("Enter Floors: ");
int floors = Convert.ToInt32(Console.ReadLine());
while(i < floors) { Console.WriteLine ("You are now in "+ floors +" floors"); break; i++; } } }
while(i < floors) { Console.WriteLine ("You are now in "+ floors +" floors"); break; i++; } } }

That is what they wanted
I cheated
It makes sense when I see it I just couldn’t figure it out
This stuff is tough man and the app is a horrible place to learn
so this is why remainder is the optimal way to do this, im not good at explaining math so sorry about that...
In c#,
N % 5 == 0
where N is the floor, is equivalent to testing the left and right side to match 0.
The expression is a - (a / b) * b
which in your code would translate to floor - (floor / 5) * 5
For example:
17 % 5 is 2 so its not equal to 0
- 17 divided by 5 is 3,
- 3 multiplied by 5 is 15
- 17 - 15 is 2
- so not divisible by 5
Ah but why its 3 and not 3.4 because we are doing integer division so the decimal places are left out.
Another example:
16 % 5 is 1 so its not equal to 0
- 16 divided by 5 is 3,
- 3 multiplied by 5 is 15
- 16 - 15 is 1
- so not divisible by 5
Now an example that hits the spot:
15 % 5 is 0 so its what we expect
- 15 divided by 5 is 3,
- 3 multiplied by 5 is 15
- 15 - 15 is 0
- so this number is divisible by 5
so all we need to test is
well what happens when the input isn’t divisible by 5 ?
it won't match 0 so it will not enter the condition so nothing gets printed
So the building has 17 floors
It wants to see there will be a restaurant on the 5th, 10th, and 15th floor
Or example
You have 23 floors
it will print only the floors where there are restaurants
Im still not tracking
ok so we are looking for restaurants on the following floors
5,10,15,20 in the event of a 23 floors building correct?
Yeah
this is more of a mathematical question then programming
so we start our loop
we are at floor 23
23 - (23 / 5) * 5
23 / 5 = 4
4 * 5 = 20
23 - 20 = 3
3 is not 0
so this floor does not have a restaurant
then our loop decrements by 1
22 - (22 / 5) * 5
22 / 5 = 4
4 * 5 = 20
22 - 20 = 2
2 is not 0
so this floor also doent have a restaurant
then our loop decrements by 1
let's skip 21 and go to 20
just for the sake of simplifying going down every floor
I see
20 / 5 = 4
4 * 5 = 20
20 - 20 = 0
so this floor have a restaurant
floor 15
15 / 5 = 3
3*5 = 15
15-15 = 0
so this floor also have a restaurant
so its literally math
Yeah yeah
That’s an interesting way to code it
the remainder is doing all that work for u
you say that is a better way to do it ?
leowest
REPL Result: Success
Console Output
Compile: 475.192ms | Execution: 42.523ms | React with ❌ to remove this embed.
im saying its the most optimal way to do it
Interesting
a lot of the stuff ur doing right now arent much of coding but more of mathematical
Is that standard when learning ?
or rather solvable with math
May I ask how you learned C#
when learning arithmetic operators sure
to some extent
I've learned a few language before reaching c# been coding for many years...
understanding remainder can be a bit difficult but its simple math.
I understand the code you did
and all of what I said above is explained on the documentation for it

I understand when reading it
but to brainstorm and think of it myself is just not there yet
the other way u could do which is simpler
would be by counting to 5
but then u would need to start from the bottom
and reset the counter every time u reach 5
that is the most simplestic way
I appreciate your help.
You seem to be well educated on this stuff
Are you an employed programmer ?
most people u will meet here are contractors or employed in some way, some aspiring to or even hobbyist programmers this community is massive, including people that work at Microsoft are in this discord
Thats crazy to think about
I could be receiving help by a GTA 6 dev haha
well u would need to be in a c++ discord I guess 😛 but for gta mods yeah
Well I look forward to learning. I’ve been playing around with unity when im at home. I follow beginner level game dev guides
yeah my advice to you is, dont worry about unity until u learn the fundamentals of c# using console apps
it will make your life 100x easier on unity side
a very easy going video I like to recommend is https://learn.microsoft.com/en-us/shows/csharp-fundamentals-for-absolute-beginners/
its very slow paced, its a bit outdated but still good
and the person explains every little bit very detailed
I will be watching that
I’m using the sololearn app
think it will help u understand alot of things
never heard of it, what is the site?
It’s like duolingo for coding lol
It’s a mobile application
but they have a site I assume?
I’m sure lemme see
do you not have a pc?
Sololearn: Learn to Code
Join Now to learn the basics or advance your existing skills
I have a pc for home
I have a lot of free time at work so I use the mobile app while I’m here to learn.
I see, I cannot imagine learning or coding on mobile
Some call it dedication
Hahaha
I mean if it works for u... but having a proper IDE makes a world of difference for learning
Yeah I have the Visual Studio and all installed at home. I’ve been learning there too
I paid for a C# fundamentals course online and the instructor created code games.
Like rock paper scissors and bulls and cows
bulls and cows? never heard of that one
paid where udemy or something?
Yes
Udemy was it
I see, I am not much of a fan due to all the overselling they do with poor quality
hope the teacher and course u got are different
Yeah it appears the Microsoft link is just about the same material he covered lol
yeah I mean the fundamentals dont change much and they are all over the internet
Maybe I need repetition with it for it to truly stick.
the difference would be the teacher actually explaining things to u on a 1 on 1 or properly having all the material u actually need without forcing u to search around your self to understand things
yes repetition is good but dont do repetition aim less
try doing some projects with some goal
even if a console text based app
Up until now I’ve been following YouTube guides and copying their code only understanding half of it
I’ll never learn that way
well if you can break it down and understand what it is actually doing its one thing
but if u just copy and paste without even understanding it then yes
sometimes I can follow
other times I’m lost
that's why learning the fundamentals help, it introduces you to all the basics from using the ide, to what your code is, what code blocks are what scopes are and how they influence your code, what methods are, variables, types, loops, etc
yeah there’s just so much
yes you wont learn a language in 24hrs
I honestly think learning Spanish is easier 😂
it takes time
once u learn the fundamentals try doing a more complete project like the rock paper scissors or hangman or even a bank app
in console it will show u where ur lacking etc
and what u need to review etc
Yeah that’s a challenge
if u can learn most of the topics in that link I posted above it will be easy
anyway good luck to u, if u have more questions just open a new thread $close
if any one flames or bully or anything u can just call a mod people here are very friendly and more than whiling to intervene if needed.
If you have no further questions, please use /close to mark the forum thread as answered
thanks again
It's not the most optimal way, it goes through each element and check if it's divisible by 5 or not while the other method is more optimal in which you start from 0 and increment 5 unless you go out of the bounds . Because the task is to only print out the multiples of 5
the most optimal way the way he was doing it with a while loop decrementing the value, yes.
I did say there was other ways to do it, that would be simpler for him to understand
You're free to provide your own solution.
cant this be done with a simple % operator?
for
loop to increment by one every time and when i % 5 == 0
print i
?
and for
loop ends when i > 10