C
C#2y ago
nks1fu

❔ ✅ 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
28 Replies
nks1fu
nks1fu2y 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
HimmDawg
HimmDawg2y ago
You said you were debugging the code. Until which line did it work?
nks1fu
nks1fu2y 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
HimmDawg
HimmDawg2y 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? 😄
nks1fu
nks1fu2y ago
omf brackets thats the whole problem? wait nope still hm
HimmDawg
HimmDawg2y ago
But you should be able to debug now goblinnSip speaking
nks1fu
nks1fu2y 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?
HimmDawg
HimmDawg2y ago
So it crashes or does it jump elsewhere?
nks1fu
nks1fu2y ago
no just stops and the close messege it doesnt jump to the printing part nor crashing
nks1fu
nks1fu2y ago
TSJN
TSJN2y ago
if statements can still work without brackets. They're used for readability
nks1fu
nks1fu2y ago
oh ty never knew that or just forgot
TSJN
TSJN2y ago
And defining which code block to execute if true etc
HimmDawg
HimmDawg2y 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;
}
nks1fu
nks1fu2y 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 :((
TSJN
TSJN2y ago
I believe only the first line of code after the condition is executed if no brackets are used
nks1fu
nks1fu2y ago
even though neither of them printed only return worked
HimmDawg
HimmDawg2y ago
Soo, what are your inputs for the animal properties then?
nks1fu
nks1fu2y ago
after it gets to inputing that part its just stops no crashes
HimmDawg
HimmDawg2y ago
Thonk
nks1fu
nks1fu2y ago
wait what how
HimmDawg
HimmDawg2y ago
That doesn't make sense. If you fixed the curly bracket stuff, it should work then
nks1fu
nks1fu2y ago
HimmDawg
HimmDawg2y ago
Sounds stupid, but maybe give your visual studio a restart? I don't see any mistakes anymore fluffyFoxThink
nks1fu
nks1fu2y 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
HimmDawg
HimmDawg2y ago
fedora
nks1fu
nks1fu2y ago
i forget brackets always mb bc coming from python ty and have a nice day !close
Accord
Accord2y 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.