Almost There

In line 19 the inputs should be displayed in descending order but it remains the same as ascending and in line 59 the function seems to be alright but unfortunately it is not working. I have been trying it but just couldn't figure out what I am doing wrong, so please help!!



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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
  #include <iostream>
#include <ctime>

using namespace std;


void Swap(double  &a, double & b);
void Sort(double* input1, double* input2, bool ascending);
double ReplaceIfGreater(double* pDouble, double input);
int main()

{
	double inputs1, inputs2, inputs3, inputs4;
	cout << "please enter two doubles : " ;
	cin >> inputs1 >> inputs2;
	Sort(&inputs1, &inputs2, true);
	cout << "The doubles in ascending order are: " << inputs1 << ", " << inputs2 << endl;
	Sort(&inputs1, &inputs2, false);
	cout << "The doubles in descending order are: " << inputs1 << ", " << inputs2 << endl;
	cout << "Please enter two more doubles:" ;
	cin >> inputs3;
	cin >> inputs4;
	double value = ReplaceIfGreater(&inputs3, inputs4);
	cout << "The return value of ReplaceIfGreater is " << value << " and the pointer value is: " << inputs4 << endl;
	return 0;
}

void Swap(double & a, double & b)

{

	double c;
	c = a;
	a = b;
	b = c;
}
void Sort(double* input1, double* input2, bool ascending)
{
	double number1 = *input1;
	double number2 = *input2;

	if (ascending)
	{
		(number1 > number2);
		Swap(number1, number2);
		ascending = true;
	}
	else
	{
		(number1 > number2);
		Swap(number1, number2);
		ascending = false;
	}
	return;

}


double ReplaceIfGreater(double* pDouble, double input)
{

	double FirstDouble = *pDouble;


	if (FirstDouble>input)
	{
		Swap(FirstDouble, input);
		return FirstDouble;

	}
	else
	{
		return input;
	}
}
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
void Sort(double& number1, double& number2, bool ascending)
{
	if (ascending && (number1 > number2))
	{
		Swap(number1, number2);

	}
	if (!ascending && (number1 < number2))
	{
		Swap(number1, number2);

	}
}
Topic archived. No new replies allowed.