-
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.
-
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.
-
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!
-
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.
-
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...
-
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.