1 dem. arrays- issue with calculations

Hello- I have to stay in 1d with an array and cannot get calculations to work to save my life. Any assistance with this would be much appreciated.

I will include the input file. You will need to save the following to a notepad file and save it as "input4.txt" The input file will need to be in the same directory as the program:

Snow White 77 87 76 82 65 90
Jack Frost 67 77 87 88 86 80
Sleeping Beauty 90 89 78 88 86 85
Prince Charming 92 87 88 89 90 91
Rapunzel Repunzel 66 76 73 81 85 70
Santa Claus 90 89 95 86 88 94
Miss Horner 65 76 72 50 69 75



Now here is what I have so far:

My issue: I need to ad up the first three scores for each "student" and have it output to the screen.

Thanks for your help.


//IT 210 Business Applications with C++
//Programmer :Mike Davis
//Date: November 2, 2009
//Functions, functions, and functions

#include<iostream>
#include<iomanip>
#include<fstream>
#include<conio.h>

using namespace std;

//Global Variables/constants, function prototypes
void headerfn();
void inputfn(string fnames[40], string lnames[40], float prog1[40],
float prog2[40], float prog3[40], float test1[40],
float test2[40], float test3[40], int &counter);
void outputfn(string fnames[40], string lnames[40], float prog1[40],
float prog2[40], float prog3[40], float test1[40],
float test2[40], float test3[40],int counter);
int totalPts(float prog1[40],
float prog2[40], float prog3[40], float test1[40],
float test2[40], float test3[40], float totalPts);
void outputfn2(string fnames[10], string lnames[10], float prog1[10],
float prog2[10], float prog3[10], float test1[10],
float test2[10], float test3[10],int counter);

ifstream fin;

//function definitions


int main(){
system("color f0");
headerfn(); //void function call

fin.open("input4.txt");
if(!fin){
cout<<"input failure";
system("pause");
return 1;
}

int counter=0;
string fnames[40];
string lnames[40];
float prog1[40], prog2[40], prog3[40], test1[40], test2[40], test3[40];
inputfn(fnames, lnames, prog1, prog2, prog3, test1, test2, test3, counter);






outputfn(fnames, lnames, prog1, prog2, prog3, test1, test2, test3, counter);


for(int row=7; row<40;row++){
prog1[row]= prog2[row]= prog3[row]= test1[row]= test2[row]= test3[row]=0;}

float totalPts=0;


for(int col=0; col<7; col++){
totalPts =totalPts+prog1[col];
}
cout<<totalPts<<endl;


cout<<endl;
//calculations



cout<<endl;

system("pause");
return 0;
}//End of Main

//******************************************************************
//void function without parameters
void headerfn(){
cout<<"************************************************\n";
cout<<"* IT 210 Business Applications with C++ *\n";
cout<<"* Programmer :Mike Davis *\n";
cout<<"* Date: November 5, 2009 *\n";
cout<<"* *\n";
cout<<"* Program Assignment 4: Student Grades 4 *\n";
cout<<"* *\n";
cout<<"* This program uses functions to read *\n";
cout<<"* student information from an input text *\n";
cout<<"* file into string and integer arrays. *\n";
cout<<"* It then calculates and outputs avgs *\n";
cout<<"* and grades to the monitor as well as *\n";
cout<<"* to an output text file *\n";
cout<<"************************************************\n";

}//end of headerfn
//******************************************************************
//input function
void inputfn(string fnames[40], string lnames[40], float prog1[40],
float prog2[40], float prog3[40], float test1[40],
float test2[40], float test3[40], int &counter){

while(fin&&counter<40){
{fin>>fnames[counter]>>lnames[counter]>>prog1[counter]>>prog2[counter]>>
prog3[counter]>>test1[counter]>>test2[counter]>>test3[counter];}
counter++;
if(fin.peek ()=='\n')fin.ignore();
}
}
//******************************************************************
//total points calculation function
int totalPts(float prog1[40],
float prog2[40], float prog3[40], float test1[40],
float test2[40], float test3[40], float totalPts){
totalPts= prog1[40]+prog2[40]+prog3[40]+test1[40]+test2[40]+test3[40];

cout<<totalPts;
}
//******************************************************************
//output function
void outputfn(string fnames[40], string lnames[40], float prog1[40],
float prog2[40], float prog3[40], float test1[40],
float test2[40], float test3[40],int counter){




cout<<"1234567890123456789012345678901234567890123456789012345678901234567890"<<endl;
cout<<"======================================================================"<<endl;
cout<<left<<setw(20)<<"Student"<<setw(10)<<"Total"<<setw(10)<<"Program"<<setw(10)<<"Test"<<setw(10)<<"Course"<<setw(10)<<"Grade"<<endl;
cout<<left<<setw(20)<<" "<<setw(10)<<"Points"<<setw(10)<<"Average"<<setw(10)<<"Average"<<setw(10)<<"average"<<setw(10)<<" "<<endl;
cout<<endl;




}

//*************************
//output function
void outputfn2(string fnames[10], string lnames[10], float prog1[10],
float prog2[10], float prog3[10], float test1[10],
float test2[10], float test3[10],int counter){

for(int row=0; row<7;row++)
{
cout<<left<<setw(20)<<fnames[row]+" "+lnames[row]<<setw(10)
<<prog1[row]<<setw(10)<<prog2[row]<<setw(10)<<prog3[row]<<setw(10)
<<test1[row]<<setw(10)<<test2[row]<<setw(10)<<test3[row]<<endl;
}
}
Is there a question in there somewhere? What exactly do you need help with?

Do you have compiler errors?
Are you not getting the output you expect?
Is the program crashing?
Yes- the question is burried in there. But I need to be able to add the first 3 scores of each user and have a total for each 3 users.

Right now, its adding the first score of every user and totaling it. I need it to total the other way- only total for each user.
Topic archived. No new replies allowed.