❔ Trying to find a way so it shows the sum of all the numbers entered and the also the average.
36 Replies
Well, how do you think you might approach that?
by creating a static string that contains the sum of all numbers
Why a string?
And why static?
Wouldn't a numeric variable of some kind make more sense?
something like that?
I think you just need a local variable.
Not a static field.
If you want to add numbers in C# you use a type like
int
mtreit
REPL Result: Success
Console Output
Compile: 578.810ms | Execution: 69.356ms | React with ❌ to remove this embed.
hmm yea that i know but its the numbers i have entered that i want to add up together
What if you declare a variable
sum
outside of your loop?like that?
You should assign it an initial value.
int intsum=0;
Now you just need to write the code so that at the end that variable contains the sum of all the input values.
i think it has to do something with this
Uh...
mtreit
REPL Result: Success
Result: int
Compile: 354.892ms | Execution: 23.888ms | React with ❌ to remove this embed.
I don't know what you're trying to do there.
basically all these numbers and make a sum of all the entered numbers
I understand that part, just not what you were trying to show with int.MinValue and int.MaxValue
You just need to add to the sum variable...
the min is the show the lowest value of all the numbers entered then the second loop is just to show up the max value out of all numbers entered
Oh you are also getting min and max, as well as sum and average.
yea
Why would you add the min value to the entered value?
for this part?
Yes...
i think its a static int
I don't think you made it static but anyway that's not really relevant to what I was trying to ask.
Why are you adding min into the sum?
i guess it didnt work
nevermind
it works now
didnt understand the logic on how it worked here .. just my moving the line inside the if
also thanks for helping !
Sure
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.