CPPForSchool.com: Variable, Operator & Expression Set 1: Assignment 7

7. Write a program to swap the values of two variables.

This program was not too difficult.  Swapping values between two variables will require a third variable, specifically to act as a placeholder for temporary storage.  Basically, once the user inputs a value for the first variable, it is immediately placed into temporary storage.  Once the user inputs the second value, it is copied over to the first variable followed by copying the placeholder value into the second variable.



To keep things simple, I tested the code by inputting 1 as x value and 2 for the y value.




Comments

Popular posts from this blog

CPPForSchool.com: Variable, Operator & Expression Set 1: Assignment 9

CPPForSchool.com: Array - Single Dimension Set 1 Assignment 6

CPPForSchool.com: Variable, Operator & Expression Set 1: Assignment 8