FAQ: Working with Numbers - Built-In Methods

This community-built FAQ covers the “Built-In Methods” exercise from the lesson “Working with Numbers”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Learn C#

FAQs on the exercise Built-In Methods

There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply (reply) below.

If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head here.

Looking for motivation to keep learning? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

This was a little confusing as I didn’t know where to add ‘Math.Floor(Math.Sqrt(Math.Abs(number)));’ (Step 4).
At first, I was trying to put it into the Math.Floor for numberTwo and tried a couple of different things before I realised that the Math.Foor is also in the double!

Could do with a little more clarity here to specify further where Math.Abs() should go. I worked it out eventually, which I suppose is positive for an aspiring coder!

using System;

namespace LowestNumber
{
  class Program
  {
    static void Main(string[] args)
    {
      // Starting variables 
      int numberOne = 12932;
      int numberTwo = -2828472;

      // Use built-in methods and save to variable 
			Math.Sqrt(numberOne);
      Math.Floor(Math.Sqrt(numberOne));
      double numberOneSqrt = Math.Floor(Math.Sqrt(numberOne));

      // Use built-in methods and save to variable 
			Math.Sqrt(numberTwo);
      Math.Floor(Math.Sqrt(numberTwo));
      double numberTwoSqrt = Math.Floor(Math.Sqrt(Math.Abs(numberTwo)));

      // Print the lowest number
			Console.WriteLine(Math.Min(numberOneSqrt, numberTwoSqrt));
      

    }
  }
}

1 Like

Had the same issue. Nowhere does it talk about ‘Math.Floor’ anywhere. Pissed me off, sat here for an hour not wanting to click the help for learning reasons, but little did I know I wasn’t even taught the question. :rage:

At the top of the instructions, we see the following:

1 Like

Show me it from the whole view. My example had no numbers in any of the parentheses. This is a different view from what we have in the lesson. Or maybe it changes for person to person when you take a placement test asking your skill level, is the content different or the same?

Perhaps I’m missing something here but it cleared appropriately and checked off so that I can go to the next lesson however, with this solution I’m still getting the “Something’s wrong with the code” error, even though I can now continue.

  // Starting variables 
  int numberOne = 12932;
  int numberTwo = -2828472;

  // Use built-in methods and save to variable
  double numberOneSqrt = Math.Floor(Math.Sqrt(numberOne));
  

  // Use built-in methods and save to variable 
  double numberTwoSqrt = (Math.Floor(Math.Sqrt(Math.Abs(numberTwo)));


  // Print the lowest number
  Console.WriteLine(Math.Min(numberOneSqrt, numberTwoSqrt));

Program.cs(18,73): error CS1026: ) expected [/home/ccuser/workspace/csharp-working-with-numbers-built-in-methods-numbers-csharp/e6-workspace.csproj]

The build failed. Fix the build errors and run again.

2 Likes

Hello, @faxxleton.

Looking at your code, and the error you’ve referenced, I’m guessing this is line 18:

The error message is telling you that a ) is expected. Looks like a ( could be removed instead if you like.

The SCT for the exercise evidently doesn’t test that your code compiles, and runs to completion. It is only testing whether your code contains certain elements. Your code contains the elements necessary to pass the SCT, but includes something extra which prevents it from compiling.

1 Like

Not sure this is what java was referring to, but I got frustrated regarding the inclusion of Math.Floor() in the answer to this section.

My annoyance with it stemming from the fact the instructions don’t explicitly ask you to include this built-in method, nor does it seem necessary. We are asked to determine which of the two square-rooted numbers is smaller, and that’s it.

Obviously the square-rooted numbers come out with decimalised answers, but it doesn’t hurt anything to just use them, so there’s seemingly no reason to need to use Math.Floor(). And again, nothing is explicitly stated asking for it to be used, so it was rather frustrating when I entered the code for the first step and got an error just because I’d left Math.Floor() out.

Hello, @efwa1984, and welcome to the forums.

Let me preface my response with the fact that moderators here on the forums are not Codecademy staff, and have nothing to do with the curriculum on the main site. We voluntarily spend time helping out, and answering questions when we can.

The instructions in question here are included in the following screenshot.

The instructions do specifically ask us to:

…find the square root of numberOne and round the answer down so it doesn’t have a decimal.

It also includes the hint shown in the screenshot. Given the descriptions of the methods shown in the instruction pane and the hint, it seems fairly clear what was expected, but that is only my opinion. If you’ve found the instructions to be unclear or ambiguous, feel free to submit your feedback directly to Codecademy by clicking the Get Help icon in the lower right corner of the screen, and then on Bugs, to complete a bug report.

1 Like

Wow…I feel stupid. I re-read that instruction several times, including during writing my post just to be sure, and somehow I apparently managed to scan over the bit about rounding down completely! I completely retract my statement/complaint and apologise.

1 Like

No apologies necessary to me. I wasn’t offended. Carry on, and Happy Coding!

You need to use so many math built in method to especially Abs as below:

  double numberOneSqrt=Math.Floor(Math.Sqrt(numberOne));

  // Use built-in methods and save to variable 

  double numberTwoSqrt=Math.Floor(Math.Sqrt(Math.Abs(numberTwo)));

  // Print the lowest number

  Console.WriteLine(Math.Min(numberOneSqrt,numberTwoSqrt));

}

}

}

Hello,

I was wondering where in the Microsoft docs I can specifically lookup things like the methods for the Math functions in this exercise. I looked around for a bit and saw some similar reference in visual basic, but I feel like that’s not what I am looking for. I was looking around here.

Thanks in advance!

Try here: