Solved

Using % in C++

Posted on 2004-09-25
4
231 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
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 additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

821 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