What did my friend do?

I am attempting to understand what a friend coded for me. I was supposed to get 3 int values and output them in order from lowest to highest. I got zero points for this. (I missed the part where I was not allowed to use nested if else statements) However, my instructor also told me that my logic was not sound. My friend insists this will work, but I am mostly confused with why he assigns the variables like this below:
numberTemp = numberOne;
numberOne = numberTwo;
numberTwo = numberTemp;

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
  //Read the three integers from the input file.
	fin >> numberOne >> numberTwo >> numberThree;

	//Output the column headings and the three numbers in those columns
	fout << "Task 5 - Ordering 3 Numbers" << endl;
	fout << setw(DIVIDER_WIDTH / 6) << "Order" 
		 << setw(DIVIDER_WIDTH / 6) << "Number 1" 
		 << setw(DIVIDER_WIDTH / 6) << "Number 2" 
		 << setw(DIVIDER_WIDTH / 6) << "Number 3" << endl;
	fout << setw(DIVIDER_WIDTH / 6) << "Original" 
		 << setw(DIVIDER_WIDTH / 6) << numberOne 
		 << setw(DIVIDER_WIDTH / 6) << numberTwo 
		 << setw(DIVIDER_WIDTH / 6) << numberThree << endl;

	//Order the numbers in ascending order
	// See if two is the largest
	if (numberTwo >= numberOne && numberTwo >= numberThree)
	{
		numberTemp = numberOne;
		numberOne = numberTwo;
		numberTwo = numberTemp;
	}

	//See if three is the largest
	else if (numberThree >= numberOne && numberThree >= numberTwo)
	{
		numberTemp = numberOne;
		numberOne = numberThree;
		numberThree = numberTemp;
	}
	
	//Determine the middle number
	if (numberTwo < numberThree)
	{
		numberTemp = numberThree;
		numberThree = numberTwo;
		numberTwo = numberTemp;
	}

	//Output the ordered numbers
	fout << setw(DIVIDER_WIDTH / 6) << "Ordered" 
		 << setw(DIVIDER_WIDTH / 6) << numberThree 
		 << setw(DIVIDER_WIDTH / 6) << numberTwo 
		 << setw(DIVIDER_WIDTH / 6) << numberOne << endl;
closed account (48T7M4Gy)
I am attempting to understand what a friend coded for me


I must be missing something here, but wouldn't it make more sense if you coded it yourself?
I am mostly confused with why he assigns the variables like this below:
numberTemp = numberOne;
numberOne = numberTwo;
numberTwo = numberTemp;


1. Put the value from numberOne into a temporary variable, numberTemp, so that you can overwrite numberOne while keeping the value.
2. Overwrite numberOne with numberTwo's value.
3. Overwrite numberTwo with numberOne's original value, found in numberTemp.

My friend insists this will work, but I am mostly confused with why he assigns the variables like this below:



Why don't you ask him/her?
Have you compile it? What errors are you getting?
Does the program work like it should? Based on the instructor's comments, most likely not.
I agree with the instructor, the logic does not make sense.
As kemort mentioned, I would recommend you do the coding. then comeback here with any issues that you may have.

Good luck!



Does the program work like it should? Based on the instructor's comments, most likely not.
I agree with the instructor, the logic does not make sense.


The instructor's comment was in response to OP's solution, not OP's friend's solution which is posted here. OP's friend's solution makes sense.
@ Tallyman, thanks for the clarification about the OP's solution.
Topic archived. No new replies allowed.