Solved

Using % in C++

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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

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…
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
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 be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

740 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