Skip to content

Trying to learn the basics of C#

Jeffrey Jordan

Asked May 3, 2019, 5:23 PM EDTSolved
Share
LinkedInX
Hi, I'm working on challenges to help me get used to c#. I know some c++, but I have a class next semester that is using c#, and I want a leg up.
 
The challenge is to find r2 given that (r1+r2) / 2 = s , or rather, the mean of two numbers. 
You're given r1 and s, so you use math or logic to find r2.
 
I can do this in two different ways. The first, is just algebra, and the other is a loop.
It's giving me a run-time error which can mean too much memory or compilation time too long.
 
Can anyone tell me why my code attempts are sketchy?
 
Thank you. 

4 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • Manoj Bhoir
    ✓ Accepted answer+2
    Hi,
     
    You can try this.
     
    +2
  • 0
    Additionally, I used Round.Math(i) in the loop one  for one attempt as well.
     
    and just an example in case the challenge didn't make sense
     
    (11 + x) / 2 = 15
     
     x = 19
     
    19 + 11 = 30 
     
    30 / 2 = 15
     
     
    I'm not trying to insult anyone's intelligence except my own. I suck at explaining. 
    0
  • 0
    Manoj >>
     
    Thanks for replying!
     
    What's the difference between parsing to int and the convert to int16?
     
    Secondly, what is int16? haha 
    0
  • Manoj Bhoir
    0
    Hi,
     
    Parsing is nothing but converting your first object type into second object type. For example converting String to Integer or Double to String and so on. Parsing can be done using many ways.
     
    In C#, Convert.ToInt16 Method Converts a specified value to a 16-bit signed integer.
     
     
    int is a primitive type allowed by the C# compiler, whereas Int32 is the Framework Class Library type (available across languages that abide by CLS). In fact, int translates to Int32 during compilation. Also, In C#, long maps to System.Int64, but in a different programming language, long could map to Int16 or Int32.
     
    0