c#, Apples for Friends, Basic Concepts, 10.2 Practice is very confusing | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

c#, Apples for Friends, Basic Concepts, 10.2 Practice is very confusing

I have attached the question and the "given broken program", can someone steer me in the right direction? Increment & Decrement Operators Tom, Bob and James have 2,3 and 4 apples accordingly. The given program should equally redistribute the apples among them, but something is wrong. Fix the program. using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace SoloLearn { class Program { static void Main(string[] args) { //your code goes here int applesTom = 3; int applesBob = 2; int applesJames = 4; //change the code Console.WriteLine(--applesTom); Console.WriteLine(applesBob++); Console.WriteLine(applesJames--); } } }

28th Dec 2020, 9:17 PM
Eric Rogers
Eric Rogers - avatar
4 Answers
+ 6
How many apples should they all have? 3+2+4=9 9/3=3 each This means Tom already has the correct amount. No change needed for Tom. Bob needs 1 more and James needs 1 less. Remember the difference between pre and post increment/decrement. For pre the value of the variable is first changed then that new value is used. For post the current value is first used and then it is changed.
28th Dec 2020, 9:27 PM
ChaoticDawg
ChaoticDawg - avatar
+ 3
ChaoticDawg I got it!!! Oh God. That was so easy, I was waaaay over complicating it. I super appreciate it.
30th Dec 2020, 1:45 AM
Eric Rogers
Eric Rogers - avatar
0
My code: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace SoloLearn { class Program { static void Main(string[] args) { //your code goes here int applesTom = 3; int applesBob = 2; int applesJames = 4; //change the code Console.WriteLine(applesTom); Console.WriteLine(++applesBob); Console.WriteLine(--applesJames); } } }
6th Jul 2021, 4:54 AM
Hoshimjonov Hojiakbar
Hoshimjonov Hojiakbar - avatar
0
I still don't understand what I am supposed to do. Am I just suppose to change the increment/decrement or am i suppose to make an if/else statement?
5th Sep 2021, 1:25 AM
Blerple Perple