View Single Post
Join Date: Jan 2008
Posts: 3,765
Reputation: VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute 
Solved Threads: 493
Featured Poster
VernonDozier VernonDozier is offline Offline
Senior Poster

Re: Where does Modulus fit in with PEMDAS?

 
0
  #2
Nov 9th, 2008
When in doubt, write a program! It's faster and more accurate than research. I did this on Dev C++, but is it a reasonable assumption that it's the same everywhere?

  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main ()
  5. {
  6. int a = 8 * 9 % 5;
  7. cout << a << endl;
  8. a = 10 % 3 * 2;
  9. cout << a << endl;
  10. cin.get ();
  11. return 0;
  12. }

Answers are 2 and 2, so it looks like * and % have equal precedence, so left takes precedence over right, as with multiply and divide. Thus you need another choice in your poll. It's one of the reasons I never liked "PEMDAS". If all you remember is the acronym, you always multiply before dividing, which is wrong, and you always add before subtracting, which is also wrong. So I think it's:

PE[MD%][AS]

Operations inside the brackets have the same precedence.
Last edited by VernonDozier; Nov 9th, 2008 at 4:09 am.
Reply With Quote