Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6613107
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:10:44+00:00 2026-05-25T20:10:44+00:00

For my C++ class, the instructor said he will give a score of zero

  • 0

For my C++ class, the instructor said he will give a score of zero to any program submitted with magic numbers. He said, even for formulas such as calculating the area of a circle (where it is common knowledge that 3.14159 is the value of Pi, we should either use a const variable or a #define directive to represent Pi and then use that in the formula).

With that said, I’m doing a financial calculation where I am determining the amount of a bill before tax. A snipet from the function is:

mealCostBeforeTax = billAmount / (1.0 + taxRate_);

The taxRate_ is an argument passed to the function as a decimal percent (e.g. 0.08). So in order to determine the amount before the tax, I have to add 1 to the taxRate making it 1.08.

My question is, since to the instructor 1.0 is a magic number. What is an appropriate name for that value?

This leads also to another question. When I am using formulas, is there a resource or a direction I can be pointed with help in understanding what certain constants in functions are called, or what they represent.

For example, when converting a temperature from Celsius to Fahrenheit, the formula is Tf=(9/5)*Tc+32. How does one find out what 9/5 represents as well as the 32. I would assume that 32 is the freezing point of water on the Fahrenheit scale, but that is just a guess. The 9/5 I would imagine is some kind of ratio between the scales, but these are guesses.

Sorry for the wall of text. But I really wanted to write a thorough question so that hopefully others may find it useful.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T20:10:45+00:00Added an answer on May 25, 2026 at 8:10 pm

    All in all, I think calling the 1.0 in this formula a magic number is a little extreme. Not every literal number is necessarily a magic number. The point is to make your code readable such that the person looking at it won’t have to guess why you picked that number out of thin air.

    In this case, I think the solution would be to wrap the calculation in a function instead of trying to come up with a #define for the 1. God help me if I ever see another program where you have a statement like #define one 1 because a programmer is following the letter of the magic number rule and not the intent.

    float getPreTaxCost(float totalCost, float taxRate);
    {
      return totalAmount / (1.0 + taxRate);
    }
    

    Especially for common formulas like converting F to C, this just makes sense. As a rule of thumb, if there is an obvious name for a constant/define that is used in a calculation definitely use it instead of a naked number in the code. However, don’t force the issue to extremes.

    I’d confirm this assumption with your prof, of course.. They can be pretty pedantic to the point of absurdity because they live in the theory and not the real world and often demand adherence to strict rules because they are rules forgetting the reason behind them.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

class Score { var $score; var $name; var $dept; var $date; function Score($score, $name,
We are currently dealing with hash function in my class. Our instructor asked us
I was at a class recently, and the instructor started a new Visual Studio
I'm stuck in an advanced ASP.NET class right now and my instructor just put
I just started taking a C++ class at my local college and the instructor
class Foo { static bool Bar(Stream^ stream); }; class FooWrapper { bool Bar(LPCWSTR szUnicodeString)
class Tag(models.Model): name = models.CharField(maxlength=100) class Blog(models.Model): name = models.CharField(maxlength=100) tags = models.ManyToManyField(Tag) Simple
class A : IFoo { } ... A[] arrayOfA = new A[10]; if(arrayOfA is
class someclass {}; class base { int a; int *pint; someclass objsomeclass; someclass* psomeclass;
class Foo(models.Model): title = models.CharField(max_length=20) slug = models.SlugField() Is there a built-in way to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.