I am really lost with this program

I know it isn't finished yet but I am having problems with it, have been trying to figure out how to fix it or complete it for two days now. So if someone can give me some help or pointers I would really appreciate it thank you


#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

// function declarations I declared all the functions I need to use.
void sortIncreasingOrder(double& a, double& b, double& c, double& d, double& e);
void getNumbersFromUser(double & a, double& b, double & c, double& d, double& e);
double sum(double a, double b, double c, double d, double e);
double average(double sum, int number);
double median(double a, double b, double c, double d, double e);
double findSmallestNumber(double a, double b, double c, double d, double e);
double findLargestNumber(double a, double b, double c, double d, double e);
void sortIncreasingOrder(double& a, double& b, double& c, double& d, double& e);
void sortDecreasingOrder(double& a, double& b, double& c, double& d, double& e);

int main()
{
// have to declare variables to use and save for the numbers of the menu and the numbers the user inputs
// I like to make my variables somethign that makes sense to me i.e. choice for the number they enter or "choice" they make
double a,b,c,d,e;
int choice = 0;

if (choice < 9)
do
{

cout << "----------------------------------------------- " << endl;
cout << "Welcome to the Jayhawk Statistical Institute " << endl;
cout << "Please enter a choice: " << endl;

cout << "1 - Enter numbers \n";
cout << "2 - Calculate sum \n";
cout << "3 - Calculate average \n";
cout << "4 - Calculate median \n";
cout << "5 - Find the smallest number \n";
cout << "6 - Find the Largest number \n";
cout << "7 - Sort numbers in increasing order \n";
cout << "8 - Sort numbers in decreasing order \n";
cout << "9 - Exit \n";
cout << "Enter Choice: \n" << endl;

cin >> choice;



switch (choice)
{

case 1:;

getNumbersFromUser (a,b,c,d,e);



break;

case 2:;

sum (a,b,c,d,e);
cout << "the sum of these numbers is: " << sum << endl;

break;

case 3:;

double avg;
double average( double sum, int number);
cout << "the average of those numbers is: " << avg << endl;


break;

default:
cout << "invalid choice" << endl;


}


return 0;
}while(choice != 9);
}

// function definitions
void getNumbersFromUser(double& a, double& b, double& c, double& d, double& e)
{
double num1,num2,num3,num4,num5;
cout << "Enter 5 Numbers" << endl;
cin >> num1;
cin >> num2;
cin >> num3;
cin >> num4;
cin >> num5;
cout << num1<< num2 << num3 << num4 << num5 << endl;

}
double sum(double a, double b, double c, double d, double e)
{
double num1;
double num2;
double num3;
double num4;
double num5;

double sum = num1 + num2 + num3 + num4 + num5;
return sum;
}
double average(double sum, int number)
{
double avg;
double num = 5;
avg = sum/num;
return avg;
}
void sortIncreasingOrder(double& a, double& b, double& c, double& d, double& e)
{
vector<double> n;
n.push_back(a);
n.push_back(b);
n.push_back(c);
n.push_back(d);
n.push_back(e);
sort(n.begin(),n.end());
a = n[0]; b = n[1]; c = n[2]; d = n[3]; e = n[4];
}
Why aren't you using vectors from the start?

If you use a vector from the start you can just pass that to each function instead of the doubles that make it up.

1
2
3
4
5
6
7
8
9
10
void getUserInput (std::vector<double> &data) // &data means pass this value by reference.
{
   double tmp; // for input holding so we can add it to the vector.
   std::cout << "Enter 5 Numbers.\n";
   for (int i = 0; i < 5; ++i)
   {
      std::cout << " >"; std::cin >> tmp;
      data.push_back(tmp);
   }
}


Here is a version of the getInput function you wrote using vectors from the start. If you rewrite your program using vectors from the start I'm sure you can fix any troubles you are having.
I am in an intro to c++ class and we haven't learned anything like that yet
the void sortincreasingorder is what was given to us before we applied any of our own code.
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

// Function Declarations 
void sortIncreasingOrder(double& a, double& b, double& c, double& d, double& e);
void getNumbersFromUser(double & a, double& b, double & c, double& d, double& e);
double sum(double a, double b, double c, double d, double e);
double average(double sum, int number);
double median(double a, double b, double c, double d, double e);
double findSmallestNumber(double a, double b, double c, double d, double e);
double findLargestNumber(double a, double b, double c, double d, double e);
void sortIncreasingOrder(double& a, double& b, double& c, double& d, double& e);
void sortDecreasingOrder(double& a, double& b, double& c, double& d, double& e);

int main()
{
	double a,b,c,d,e;
	int choice; // No need to set this yet.

// if (choice < 9) // Useless if. Do while will happen one no matter what.
	do
	{

		/* cout << */ "-----------------------------------------------\n"
		/* cout << */ "Welcome to the Jayhawk Statistical Institute\n"
		// cout << "Please enter a choice: " << endl;
		/* cout << */ "Make a selection:\n"//;
		/* cout << */ "1 - Enter numbers\n"//;
		/* cout << */ "2 - Calculate sum\n"//;
		/* cout << */ "3 - Calculate average\n"//;
		/* cout << */ "4 - Calculate median\n"//;
		/* cout << */ "5 - Find the smallest number\n"//;
		/* cout << */ "6 - Find the Largest number\n"//;
		/* cout << */ "7 - Sort numbers in increasing order\n"//;
		/* cout << */ "8 - Sort numbers in decreasing order\n" //;
		/* cout << */ "9 - Exit \n" //;
		/* cout << */ "Enter Choice.\n >";
		cin >> choice;



		switch (choice)
		{

			case 1: getNumbersFromUser (a,b,c,d,e); break;
			case 2: cout << "The sum of these numbers is: " << sum(a,b,c,d,e) << endl;
				break;
			case 3:
				// double avg;
				// double average( double sum, int number);
				// cout << "the average of those numbers is: " << avg << endl;
				// Make this a single line?
				cout << "The average of the 5 numbers is: " << avg(sum(a,b,c,d,e), 5) << endl;
				break;
			default:
				cout << "Invalid Choice" << endl;
		}
		// Bad spot for return. Its in the loop. Put it outside.
		//return 0;
	} while(choice != 9);
	
	return 0;
}

// Function Definitions
void getNumbersFromUser(double& a, double& b, double& c, double& d, double& e)
{
	/*
	double num1,num2,num3,num4,num5;
	cout << "Enter 5 Numbers" << endl;
	cin >> num1;
	cin >> num2;
	cin >> num3;
	cin >> num4;
	cin >> num5;
	cout << num1<< num2 << num3 << num4 << num5 << endl;
	*/
	// Incorrect way of getting vars. Try this:
	cout << "Enter 5 Numbers.\n";
	cin >> a >> b >> c >> d >> e;
}

double sum(double a, double b, double c, double d, double e)
{
	/* double num1;
	double num2;
	double num3;
	double num4;
	double num5;

	double sum = num1 + num2 + num3 + num4 + num5;
	return sum; */
	// You don't need to make a variable. Just do the operation in the return.
	return a+b+c+d+e;
}

double average(double sum, int number)
{
	/* double avg;
	double num = 5;
	avg = sum/num;
	return avg; */
	// Do operation in return.
	return sum/number;
}

void sortIncreasingOrder(double& a, double& b, double& c, double& d, double& e)
{
	vector<double> n;
	n.push_back(a);
	n.push_back(b);
	n.push_back(c);
	n.push_back(d);
	n.push_back(e);
	sort(n.begin(),n.end());
	a = n[0]; b = n[1]; c = n[2]; d = n[3]; e = n[4];
}


Here some fixes. Ask any question on why I may have changed something feel free to ask.
Topic archived. No new replies allowed.