|
Thread: C++
-
February 21st, 2003, 12:07 AM
#1
Senior Member
C++
Will someone tell me if there is another sign for division in C++ besides the / ??
I had a prof review a program that worked but he said the code would have been easier to read if I had used the "other" symbol for division. I hastily agreed and then couldn't find it and I know it's sitting right in front of me but I did spend a half hour looking for it, to no avail.
the only way to fix it is to flush it all away-tool
-
February 21st, 2003, 12:18 AM
#2
Senior Member
Maybe your prof meant that you could use the % symbol to obtain the remainder of division. It is not exactly another sign for division but its an operation related to a division and sometimes its really handy: 20%5=0 or 5%2=1. An example of its use will be a prog to check if a number is even or odd.
Hope this helps
I forgot something else, you could include math.h and use MOD instead of %. I don't remember if mod is case sensitive or not.
-
February 21st, 2003, 12:23 AM
#3
Senior Member
We used that in the program it's called modular somethin' ? But thanks-I gotta walk the dog and will check back later-thanks again!
the only way to fix it is to flush it all away-tool
-
February 21st, 2003, 12:54 AM
#4
Member
Yep, it's called the 'Modulus Operator'. Maybe thats what your professor meant. And yes, it can be used to check whether a number is even or odd. Very useful in circular linked lists.
I blame you cos my mind is not my own, so don't blame me if I trespass in your zone!
-
February 21st, 2003, 01:25 AM
#5
Member
Perhaps your prefesor ment to multiply by 1/ the numer which is in fact like diving..
for exaple: instead of dividing 6 into 2 (6 / 2) you can multiply 6 * 0.5 (1/2) ... arriving at the exacte same result (obiously suppousing you are working with floats or doubles)...
Well that's the only other way i know of dividing a number with out the "/"... Well you could also make a function :
double
div(double a, double b)
{
return (a/b);
}
which could also make the trick of dividing to numer without using the "/" operand... =)
Other than that; I'm afraid i can't help you...
regards...
ampm2003...
\"Aclaró que un Aleph es uno de los puntos del espacio que contiene todos los puntos\"... (An Aleph is a point in space that contains every point)
Jorge Luis Borges \"El Aleph\"...
-
February 21st, 2003, 04:59 AM
#6
Senior Member
He might have meant to divide using const variables instead of magic numbers. Ex. instead of 6 / 2 he wanted six / two. That was something my teacher always said made the code easier to read. But other than that i cant think of another way than what has been mentioned.
Ben Franklin said it best. \"They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.\"
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|