Solved

Using % in C++

Posted on 2004-09-25
4
238 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
  • 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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

860 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