c# hw help
i need to complete steps 6, 7, 8 but i am pretty lost about how to do it
12 Replies
i did step 6 but it looks weird
for (int careerIndex = 0; careerIndex < Careers.Length; careerIndex++)
{
Console.Write($"{careerIndex + 1}. {Careers[careerIndex]} (");
for (int attributeIndex = 0; attributeIndex < PrimaryAttributesShort.Length; attributeIndex++)
{
Console.Write($"{PrimaryAttributesShort[attributeIndex]}: {CareerTemplates[careerIndex][attributeIndex]}");
if (attributeIndex < PrimaryAttributesShort.Length - 1)
Console.Write(", ");
}
Console.WriteLine(")");
}
Have you tried it? Does it do what its expected to do, or is there an error?
it works but i just used youtube to type it out and i dont even understand it myself. its not stuff weve gone over in class that looks familiar
does that look like an inefficient way or advanced way or doing it
Im on my phone, sorry its hard to read here. I'm not sure I fully grasp what your professor wants but on my phone quickly skimming it looks fine
its okay your help is much appreciated it as is
It looks like a beginner way I suppose. Theres ways you can restructure the code to reduce the amount of loops you do for things but thats far beyond what your current lessons are
I'll be back in 10-15min on a computer if nobody else pops in here and I'll rewrite that code with some comments on whats going on
i just dont understand what the primaryattribute short. length -1 is and what this code even says
okay i really appreciate it
thank you
os much
.Length
gives you the number of elements. So, for an array that contains 3 elements, like [81, 45, 129]
it will give you 3
Arrays (and lists, and other collections) in C# are, however, 0-indexed
Meaning the indexes here are
array.Length - 1
is the way to get the last index of the array
In your specific example, what the code does, is it checks if the current index is less than the max index, and if so, it prints a comma
So that the output is 81, 45, 129
and not 81, 45, 129,
Is it just that bit or other bits?
@brandon https://paste.mod.gg/lrzutlxdpkuz/0
BlazeBin - lrzutlxdpkuz
A tool for sharing your source code with the world!
I've added some comments to this code
omg this is so detailed and helpful
thank you
oh i see ok thank you i was confused by it