% sign on the Miracle C Compiler

Posted on 2007-08-05
Last Modified: 2009-08-30
I want to give you all heads up. The Kudler Fine Foods Tax Calculator question is homework for sure. It is college or technical homework. The reason how I know is because I am in the middle of a class right now and that is our assignment. I am having problems with it but I seem to see a lot of questions on how to build a tax calculator. My intentions for being here is simple. I want to learn and since I am a visual learner it is way harder for me to asertain reading it. I do not want anyone to write the code for me, the questions I have are of specific nature. I hope this clears my intentions. If it seems like I am asking for more than that I am positively sure that I will be told about it, but keep in mind I am a beginner and if I am to learn it is by asking questions. All I ask is for a little help or guidance, no short cuts.

This is my first question
The significance in the percent sign. When I write 7.25% in the case staement it is in error.
here is what it looks like-       case Del Mar:
                                                        rate = 7.25%;
Now, since 7.25 is laready being multiplied by the total which is 125.00 in the program, is the percent sign throwing the compiler off becase it is not needed, or am I missing or over writing the lines? Thank you
Question by:Shadow-Ninja
    LVL 10

    Expert Comment

    The percent sign is not necessary if you want to show a rate of 7.25% you can show it as rate=.0725.  Symbols such as %,$,& always have a different meaning in programming.  % is usually used to call a variable name such as %variablename% in code but it can be used for other things.  Hope this helps.
    LVL 53

    Accepted Solution

    >>                                                         rate = 7.25%;

    duffman76 is right of course, but I wanted to add this : rate is a floating point value (I hope), and was either defined like this :

            float rate;

    or like this :

            double rate;

    (or one of their "specializations").

    A floating point value is just what it says : a value. It says nothing about what the value really means - it could be a price (in dollars), it could be the amount of fuel in a tank (in liters), ... or it could be a percentage like in your case.

    In other words, you never write :

            float price = 5.25 dollar;
            float price = 5.25 $;
            double amount = 21.23 liter;
            double rate = 7.25 %;

    Neither of the above are valid. Instead, you use :

            float price = 5.25;
            double amount = 21.23;
            double rate = 7.25;

    and write the rest of the code, assuming that the price is in dollars, the amount in liters, and the rate is a percentage.

    The exact meaning of the value is up to you, the programmer, to implement correctly in the code. Properly naming the value ("rate" in your case is good) can help a lot in clarifying what the value means.
    LVL 22

    Expert Comment

    The compiler knows nothing about the percent sign meaning "percent".  So you have to write:

    float percent;

    percent = 0.075;

    or a little bit clearer:

    float percent;

    percent = 7.5 / 100.0;


    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Join & Write a Comment

    Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
    This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
    Video by: Grant
    The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.
    The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.

    733 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now