C
C#sh1zz0_

❔ ✅ beginner class and properties

i am doing basic program abt class and getting information from input but on the weight section when i run the code it doesnt show anything even when debugging couldnt figure it out
S
sh1zz0_442d ago
Console.WriteLine("how much does the animal weigh");
temp = Console.ReadLine();
animal.Weight = Convert.ToInt32(temp);

Console.WriteLine("what dimension did u use (kg/lb)");
Dimension = Console.ReadLine();

if (Dimension != "kg" && Dimension != "lb")
Console.WriteLine("typo try again");
return;
if (Dimension == "kg" && animal.Gender == "Female" && animal.Weight > 80)
{
Console.WriteLine("Cant accept your Animal due to its weight");
return;
}
if (Dimension == "lb" && animal.Gender == "Female" && animal.Weight > 176)
{
Console.WriteLine("Cant accept your Animal due to its weight");
return;
}

if (animal.Gender == "Male" && animal.Weight > 120)
{
Console.WriteLine("Cant accept your Animal due to its weight");
return;
}
if (Dimension == "lb" && animal.Gender == "Male" && animal.Weight > 264)
{
Console.WriteLine("Cant accept your Animal due to its weight");
return;
}

Console.WriteLine(animal.Name);
Console.WriteLine(animal.Breed);
Console.WriteLine(animal.Age);
Console.WriteLine(animal.Colour) ;
Console.WriteLine(animal.Weight);
}
Console.WriteLine("how much does the animal weigh");
temp = Console.ReadLine();
animal.Weight = Convert.ToInt32(temp);

Console.WriteLine("what dimension did u use (kg/lb)");
Dimension = Console.ReadLine();

if (Dimension != "kg" && Dimension != "lb")
Console.WriteLine("typo try again");
return;
if (Dimension == "kg" && animal.Gender == "Female" && animal.Weight > 80)
{
Console.WriteLine("Cant accept your Animal due to its weight");
return;
}
if (Dimension == "lb" && animal.Gender == "Female" && animal.Weight > 176)
{
Console.WriteLine("Cant accept your Animal due to its weight");
return;
}

if (animal.Gender == "Male" && animal.Weight > 120)
{
Console.WriteLine("Cant accept your Animal due to its weight");
return;
}
if (Dimension == "lb" && animal.Gender == "Male" && animal.Weight > 264)
{
Console.WriteLine("Cant accept your Animal due to its weight");
return;
}

Console.WriteLine(animal.Name);
Console.WriteLine(animal.Breed);
Console.WriteLine(animal.Age);
Console.WriteLine(animal.Colour) ;
Console.WriteLine(animal.Weight);
}
this is where i have a problem when running it just stops the whole code from running
H
HimmDawg442d ago
You said you were debugging the code. Until which line did it work?
S
sh1zz0_442d ago
when i added 3 conditions
if (Dimension == "kg" && animal.Gender == "Female" && animal.Weight > 80)
if (Dimension == "kg" && animal.Gender == "Female" && animal.Weight > 80)
from here
H
HimmDawg442d ago
if (Dimension != "kg" && Dimension != "lb")
Console.WriteLine("typo try again");
return;

if (Dimension == "kg" && animal.Gender == "Female" && animal.Weight > 80)
{
Console.WriteLine("Cant accept your Animal due to its weight");
return;
}
if (Dimension != "kg" && Dimension != "lb")
Console.WriteLine("typo try again");
return;

if (Dimension == "kg" && animal.Gender == "Female" && animal.Weight > 80)
{
Console.WriteLine("Cant accept your Animal due to its weight");
return;
}
Notice anything? 😄
S
sh1zz0_442d ago
omf brackets thats the whole problem? wait nope still hm
H
HimmDawg442d ago
But you should be able to debug now goblinnSip speaking
S
sh1zz0_442d ago
yes but still wont only the dimension part will work? so same exact thing i still get the same thing code stops to run is the statement in incorrect form?
H
HimmDawg442d ago
So it crashes or does it jump elsewhere?
S
sh1zz0_442d ago
no just stops and the close messege it doesnt jump to the printing part nor crashing
S
sh1zz0_442d ago
T
TSJN442d ago
if statements can still work without brackets. They're used for readability
S
sh1zz0_442d ago
oh ty never knew that or just forgot
T
TSJN442d ago
And defining which code block to execute if true etc
H
HimmDawg442d ago
without curly brackets however, there's a big difference between
if (condition)
some stuff;
return;
if (condition)
some stuff;
return;
and
if (condition)
{
some stuff;
return;
}
if (condition)
{
some stuff;
return;
}
S
sh1zz0_442d ago
is it bc where return is on the other statements will that change anything even though there are brackets nope same thing good to know tho what else can be the problem i just cant think of it and been stuck for a while kinda new so :((
T
TSJN442d ago
I believe only the first line of code after the condition is executed if no brackets are used
S
sh1zz0_442d ago
even though neither of them printed only return worked
H
HimmDawg442d ago
Soo, what are your inputs for the animal properties then?
S
sh1zz0_442d ago
after it gets to inputing that part its just stops no crashes
H
HimmDawg442d ago
Thonk
S
sh1zz0_442d ago
wait what how
H
HimmDawg442d ago
That doesn't make sense. If you fixed the curly bracket stuff, it should work then
S
sh1zz0_442d ago
H
HimmDawg442d ago
Sounds stupid, but maybe give your visual studio a restart? I don't see any mistakes anymore fluffyFoxThink
S
sh1zz0_442d ago
i always make mistakes on brackets and stuck for an hour kinda miss python one sec IT WORKS ty for the help and for your time
H
HimmDawg442d ago
fedora
S
sh1zz0_442d ago
i forget brackets always mb bc coming from python ty and have a nice day !close
A
Accord441d ago
Closed! Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server
More Posts
❔ Best practice to retrieve MySQL columnsHello wonderful people! Can you please help me understanding what would be the best practice to ret❔ Auto Slide Showhere my code✅ materialDesign:Cardfor some reason it says that closing matrialcard doesent exist and it shows an error❔ Why does this code give the CS8604 warning?I'm confused why the below code gives the CS8604 warning. As far as I am concerned, I am null checki✅ Having trouble adding a picture to my code.what should the path look like?❔ Producer Consumer ISourceBlock<T>, periodically flushing consumed dataHi, I've the following scenario: I've a camera continuously acquiring frames and a c# app receiving ❔ Load async data and display it (WindowsAppSDK / WinUI3)I am currently developing my first windows app with C#, Windows App SDK and WinUI3. I want to do som❔ Best Approach to Implement Authentication and Authorization in Microservices with ASP.NET CoreHi friends, I'm looking for experience share. I have Microservices architecture project, that uses ❔ Performance of many small requests vs less but bigger requestsI have 2 projects: an API hosted on aws and a desktop application. Currently, I'm fetching around 4k✅ Image from dataurlI have dataurl with image and i need to get it to some reasonable image object in c#, so i can resiz✅ why does the test case fail?This is from a longest palindrome puzzle on LeetCode https://leetcode.com/problems/longest-palindrom❔ MongoDB Update nested elementsMongoDB question, I'm trying to add a property to all of my existing documents. The thing is, my doc❔ Grapple HookSo I just made a grapple script but I have a gun camera not the actual gun so how do I add the Grapp❔ Custom "block" statement such as while..doHello, is it possible to build a custom block? For example ```csharp // usage DoRequestAsync { ✅ Why am I getting this exception?```cs class algo{ public static void Main(string [] args){ addList.numbers(); i❔ Console.ReadKey() blockingHey there. I have this function that is called every frame: ```public void Update() { if ( !Co❔ Trouble Creating PowerShell CommandletI'm using visual studio 2022, dotnet 6.0. I installed the automation package using > NuGet\Install-P✅ Passing data from controller to viewHi guys hoping for some help here. I have an eCommerce wep app using ASP.NET MVC (7.0) and I want tHow to implement that when you click on the button the data that was sent with it will be displayedHow to implement that when you click on the button the data that was sent with it will be displayed❔ Visual Studio: How to hide tptrace output from Immediate Window during Test Explorer executions?Title says it all. Is there a way to hide the output messages from tptrace that get written to the I