Functions

How could I begin to put this program in functions like I need to have one main function, a function for the mean, one for the max/min and one for my standard deviation.

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
#include <iostream>
#include <cstdlib>
#include<cmath>
using namespace std;

double sum =0;
float std1=0;
int count,i;
int mean,number;

int main(int argc, char *argv[])
{
	if (argc != 11)
	{
		cout << "You forgot to enter more grades.\n";
        return 1;
	}
	int max = 0;
    int min = 100;
	for (i=1; i<argc; i = i + 1)
	{
			cout << "Grade" << "#" << i+0 << "is :"<< argv[i] << '\n';
			sum += atof(argv[i]);
			count ++;
			number = atof(argv[i]);

			if (number > max)
			{
				max = number;
			}
			else if (number < min)
			{
				min = number;
			}

	}
	mean = sum/count;
	cout <<"This is the mean of the grades entered:"<< mean << '\n';
	cout << "This is you're highest grade: " <<max << '\n';
	cout << "This is you're lowest grade:" <<min << '\n';
double mean2;
for (i=1; i<argc; i = i + 1)
{
	number = atof(argv[i]);
	std1 = number - mean;
	cout <<i+0 <<std1 << '\n';
	int square;
	square = std1 * std1;
	sum += square;
	mean2 = sum/count;
	cout <<i+0 <<square <<'\n';
}
cout <<mean2 <<'\n';
double deviation;
deviation = sqrt(mean2);
cout << deviation <<'\n';
	system("pause");
    return 0;
}


Any help is appreciate it thanks so much =)
Last edited on
just add functions like add, subtract, etc. e.g. :
1
2
3
4
5
6
7
double add (double num1, double num2) {
      //functions definitions
}

double sub (double num1, double num2) {
     //functions definitions
}
Last edited on
Topic archived. No new replies allowed.