Reviewing for my midterm and dont remember this..

Please help me :-D

1
2
3
4
5
6
7
8
9
10
11
12
13
14
  Given the below values and having formulas, 
what will be the values after execution
double x=48.967, y=4.5, z=3.7; int m=4, n=11, p=1;
Example
p=z;
Answer: 3
p=n/m;
Answer: 2
p=n%m;
Answer: 3
p=p+m;
Answer: 5
z=n/m+n%m+y*p*2; 


I am LOST on this one !!!!! Can anyone some what explain?? even a little?
Last edited on
The assignment wants you to perform basic formula evaluation. The only hard/tricky/annoying part is coding the formula parser. In this case though it looks like you just have to pass the given test cases, so your formula parser can be a simple one.
I am trying to figure out how he gets p=z answer =3 etc.. I am lost on this
If you are looking for

z=n/m+n%m+y*p*2;

specifically, and are just having a difficult time with that one.

http://www.cplusplus.com/doc/tutorial/operators/#precedence

This will tell you which operators to use first. It's equivalent to the middle school algebra "PEMDAS"
Last edited on
I must be doing some completely wrong. I did Arithmetic: scaling first but always end up with 14.75 I have 2 be missing something obvious. Am I suppose 2 be doing anything prior to

z=n/m+n%m+y*p*2;
Make sure you are using integer division correctly. That might be the issue.
:-D Thanks
Topic archived. No new replies allowed.