Feb 21, 2013 at 9:23pm UTC
Hi I'm taking an intro to C++ class. I'm lost on a HW assignment Trace to find the value assigned to e. Assume a, b, c are integer, d and e are double.
a. a = 3; b = 4;
b. c = ( a % b ) * 6
c. d = c / b;
d. e = ( a + b + c + d ) / 4;
If anyone can be of some help. I would really appreciate it I'm completely lost on this part of my HW assignment.
Feb 21, 2013 at 9:39pm UTC
I can give some guidelines. ASSUME each line is markings on your paper:
Now you made marking to your paper: each "a" will represents number 3 and "b" represents number 4.
In this row you say: INTEGER c is equal to what ever is leftover on dividision 3/4 and multiple it by 6 -> a%b=3%4=
3 -> c=
3 *6=18
You said d is double so: c=18, b=4 -> d=c/b ->d=18/4->d=4.5
d. e = ( a + b + c + d ) / 4;
This is easy is it yeah?
a=3
b=4
c=6
d=4.5...
make rest yourself
EDIT: error on maths. ty chervil below
Last edited on Feb 21, 2013 at 10:06pm UTC
Feb 21, 2013 at 9:52pm UTC
Yes I'm still lost can you clarify a little bit more please. For the first if a =3 b=4 then how would you solve it ?
Feb 21, 2013 at 9:54pm UTC
The words make sense. but the numbers don't.
What is 3%4 ?
3 divided by 4 is 0, remainder 3.
Feb 21, 2013 at 9:55pm UTC
a. b. c. and d. are steps you need to take to get final answer.
a = 3; b = 4;
c = ( a % b ) * 6
d = c / b;
e = ( a + b + c + d ) / 4;
removed step indicators. You were asked to produce final answer. Nothing more
EDIT: oops (ty chervil)
Last edited on Feb 21, 2013 at 10:03pm UTC