Hello,
I'm new to the board and programming and have a question that I hope someone could help me with. I have been learning about arithmetic assignment operators and was asked to write a program to calculate some values.
Upon inspecting my code, I thought it was rather inefficient to have to re-declare the variables before each printf statement to reset them. I thought it might be better to write a function that would reset the variables before each statement, but I'm not sure how to go about writing the code for the function. I was thinking along the lines of:Code:#include <stdio.h> main() { int x, y; x = 1; y = 3; printf("x += y produces an answer of: %d.\n", x += y); x = 1; y = 3; printf("x += -y produces an answer of: %d.\n", x += -y); x = 1; y = 3; printf("x -= y produces an answer of: %d.\n", x -= y); x = 1; y = 3; printf("x -= -y produces an answer of: %d.\n", x -= -y); x = 1; y = 3; printf("x *= y produces an answer of: %d.\n", x *= y); x = 1; y = 3; printf("x *= -y produces an answer of: %d.\n", x *= -y); return 0; }
but I don't know how to return the values back to main. I know this is elementary, and I probably just haven't gotten far enough in my studies to understand how to do this, but thought that someone here could lend a hand.Code:int var_reset(int x, int y) { x = 1; y = 3; }
Thank you!



LinkBack URL
About LinkBacks





