c = a + b and then d = 2*c

Hi there

This is my second question www.cplusplus.com in quick succession but any answers should benefit other beginners as well.

I know that the code c = a + b; adds the values of 'a' and 'b'.

The question is how can the following code be linked together?

c = a + b;

d = 2*c

I want to:

Step 1. Calculate 'c',
Step 2. Output 'c' using 'cout'
Step 3. Calculate the value of 'd'

The unknown part for me is how to link steps 2 and step 3 to make it work.

Thanks in advance.

Regards

James Cox
c = a + b; This calculates c, step 1 complete.

Step 2 is just to print out c. Using cout. cout << c << endl;

Now on to step 3. You already have c, so calculating 2*c should be easy.
You create a variable d, and do d = c*2;

Hope it helps.
Thank you for your clear response TarikNeaj.
Topic archived. No new replies allowed.