How to sum the column

I m the beginners.So now,i have a text file ,the content inside the text file is
2 3 5 4 2
3 5 3 2 2
1 5 4 2 4
2 5 4 1 3
3 5 4 4 4
3 5 4 1 2
3 3 3 2 2
4 4 3 1 4
2 4 5 5 3
3 4 4 4 3
3 4 4 5 4
3 4 5 4 4
2 4 4 2 4
2 3 3 3 3
5 3 4 3 3
1 4 3 1 4
3 5 3 1 3
5 4 4 4 3
3 5 3 2 4
3 3 5 4 4
3 4 3 1 3
3 4 3 2 2
4 5 3 4 4
1 3 3 3 4
3 4 5 2 4

C1 C2 C3 C4 C5
i can import the content into the program.
But the problem now,how can i sum up the column of the numbers?
i need have 5 answer below.

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

	void AveRank()
	{
	int input;
	int cour1 = 0;
	int cour2 = 0;
	int cour3 = 0;
	int cour4 = 0;
	int cour5 = 0;
	int aCour1 = 0;
	int aCour2 = 0;
	int aCour3 = 0;
	int aCour4 = 0;
	int aCour5 = 0;
    cout << "Agreement for each course is : \n";
    cout << "=====================================\n";
    cout << "Agreement for course 1 is " << aCour1 <<endl;
    cout << "Agreement for course 2 is " << aCour2 <<endl;
    cout << "Agreement for course 3 is " << aCour3 <<endl;
    cout << "Agreement for course 4 is " << aCour4 <<endl;
    cout << "Agreement for course 5 is " << aCour5 <<endl;
    cout << "=====================================\n\n";
	}
	
	void selection(){
		int input;
		cout<<"\nPlease choose a function below\n";
        cout<<"==============================\n";
        cout<<"1. Average Ranking For Each Course\n";
        cout<<"2. Lowest Average Ranking\n";
        cout<<"3. Highest Agreement\n";
        cout<<"4. Exit\n";
        cout<<"Selection: ";
        cin>> input;
        switch ( input ) {
        case 1:            // Note the colon, not a semicolon
        AveRank();
        selection();
        break;
        default:            // Note the colon, not a semicolon
        cout<<"\nError, bad input\n";
        selection();
        break;
        }
        cin.get();
	}

   int  main()
  {    
	int input;
    int array_size = 1024;               // define the size of character array
	char * array = new char[array_size]; // allocating an array of 1kb
	int position = 0;                    //this will be used incremently to fill characters in the array 
  
	ifstream fin("inCourse.txt"); //opening an input stream for file test.txt
	
    if(fin.is_open())
	{
     //file opened successfully so we are here
    cout << "File Opened successfully!!!. Reading data from file into array" << endl;
    //this loop run until end of file (eof) does not occur
		while(!fin.eof() && position < array_size)
		{
			fin.get(array[position]); //reading one character from file to array
			position++;
		}
		array[position-1] = '\0'; //placing character array terminating character
    
    cout << "Displaying Content..." << endl << endl;
    //this loop display all the charaters in array till \0 
		for(int i = 0; array[i] != '\0'; i++)
		{
			cout << array[i];
		}
		
        selection();
	}
	else //file could not be opened
	{
		cout << "File could not be opened." << endl;
	}
	return 0;
	
}
Last edited on
what error do you get ?
char array ?
it should be 2d int array.
the agreement formula is C1 = column c
2-2.8^2=0.64
3-2.8^2=0.04
1.2.8^2=3.24 and so in do until last one
3-2.8^2=0.04

after applied that ,then sum of the column C1
the answer of c1 is 26.00

so the problem i face is ,i dont know how to write a nested loop in this program. Please help me this problem


***the average of C1 is 2.80****
Please help me this question,urgent.
I do not understand your formula.

Your input data seems to be a table that has five columns. Is it correct that you want to calculate a sum for each column? How would you calculate a sum, if you would have only one column in your table?
Topic archived. No new replies allowed.