#include <iostream>
#include <fstream>
usingnamespace 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 = newchar[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;
}
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?