Solved

Using % in C++

Posted on 2004-09-25
4
250 Views
Last Modified: 2010-04-01
If I wanted to use a % sign to indicate percentage as opposed to mod .........Is this possible? what would I need to know do to do this....
I am writting a code with 12%,15%,and 18% increments.

12% rate  if gross wage <=200.00   ////    or should It be //// .12 rate if gross wage <=200.00
0
Comment
Question by:bananaamy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 55

Assisted Solution

by:Jaime Olivares
Jaime Olivares earned 100 total points
ID: 12152251
I think it can't be done.
0
 
LVL 10

Accepted Solution

by:
Sys_Prog earned 400 total points
ID: 12152804
I do not really understand your question

If u are using % sign in your calculation, then for sure it will be interpreted as mod

You will have to explicitly put 0.12 in your caculation if u need it to be interpreted as percentage

This is the case with built in data types

However, for user defned datatepes/classes, you could use operator overloading to treat this as an percentage OR a mod depending on your arguments.

Hoevere, its not recommended to change the meaning of a buit in operator

Amit
0
 
LVL 1

Expert Comment

by:Feldspar
ID: 12152820
"x = 0.12 * gross_wage" is the way to go.

Note that if you want to use an integer variable to represent the percentage, i.e. "int rate = 12" then you can use
"x = (rate/100.0) * gross_wage" - the 100.0 is to make sure the compiler uses floating point math, if you use (rate/100) it will use integer math and round that off to 0.
0
 
LVL 10

Expert Comment

by:Sys_Prog
ID: 12152900
That's OK bananaamy,

We all keep learning for the whole of life

So....best of luck for your learning adventure

Amit
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

696 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