Solved

Using % in C++

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
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…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
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…

705 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

18 Experts available now in Live!

Get 1:1 Help Now