# Thread: Use result in a new statement

1. ## Use result in a new statement

Hello,

I am in the process of learning C and I'm stuck on this code...

The object is for the user to give 2 integers which will ultimately be multiplied, subtracted and added together. The point which I get stuck at, is how to put the result of one statement into that of another:

Code:
```#include <stdio.h>

int main()
{
int a /*first input*/;
int b /*second input*/;
int c /*result of a + b*/;
int d /*result of a - b*/;
int e /*result of a * b*/;

printf("Enter the first number:");
scanf("%d", &a);

printf("Enter the second number:");
scanf("%d", &b);

c = a + b;
d = a - b;
e = a * b;

printf("\na+b=%d\n", c);
printf("a-b=%d\n", d);
printf("a*b=%d\n", e);

return 0;
}```
If the first input is 78 and the second is 83, this should be the result:

Enter the first number:78
Enter the second number:83

78+83=161
78-83=-5
78*83=6474

2. For a and b, you do the same thing you did with c.

3. Could you be more specific?

4. Could you be more specific?
I think you need to be more specific - your question really doesn't make sense with your code. If I understand you correctly, you're asking how to take the ouput of some expression and use it as the input for another expression. You're pretty much doing that here. Obviously once you have said "c = a + b", c holds a value just like a and b do. So you could say "d = a + c", or you could use c as the parameter to a function - whatever. It's a variable just like a and b.

scanf("%d", &b);

c = a + b;
d = a - b;
e = a * b;

printf("\na+b=%d\n", c);

5. Code:
```		printf("\na+b=%d\n", c);
printf("a-b=%d\n", d);
printf("a*b=%d\n", e);```
If I were to execute the program with the code as is, then the final result will display as follows:

a+b=161
a-b=-5
a*b=6474

What I really want is it to display:

78+83=161
78-83=-5
78*83=6474

To use another example. If the first input was 12 and the second 25, then the program should display:

12+25=37
12-25=-13
12*25=300

a+b=37
a-b=-13
a*b=300

Hope that helps..!

6. Code:
`printf("\n%d+%d=%d\n", a,b,c);`
Kurt

7. Thanks!! This is the result of the final code...

Code:
```#include <stdio.h>

int main()
{
int a /*first input*/;
int b /*second input*/;
int c /*result of a + b*/;
int d /*result of a - b*/;
int e /*result of a * b*/;

printf("Enter the first number:");
scanf("%d", &a);

printf("Enter the second number:");
scanf("%d", &b);

c = a + b;
d = a - b;
e = a * b;

printf("\n%d+%d=%d\n", a,b,c);
printf("%d-%d=%d\n", a,b,d);
printf("%d*%d=%d\n", a,b,e);

return 0;
}```

8. Looks good, but I suggest that you make your indentation more consistent. You could also use names that are more descriptive, e.g.,
Code:
```#include <stdio.h>

int main()
{
int input1;
int input2;
int result_sub;
int result_mul;

printf("Enter the first number:");
scanf("%d", &input1);

printf("Enter the second number:");
scanf("%d", &input2);