0

I've spent the last hour trying to figure out why my calculations are not adding up. Once i run the program it just output 0 for the total points program averages and etc and it also leaves student name blank. Can someone please help me figure out the issue.

thanks

//Preprocessor Directives
#include<iostream>
#include<iomanip>
#include<fstream>
#include<conio.h>

using namespace std;

//Global variables, constants, AND function prototypes

void headerfn(void);
void getName(string firstName, string lastName);
string firstName, lastName;
int score (int firstProgramGrade, int secondProgramGrade, int thirdProgramGrade, int firstTestGrade, int secondTestGrade, int thirdTestGrade); 
int firstProgramGrade, secondProgramGrade, thirdProgramGrade, firstTestGrade, secondTestGrade, thirdTestGrade;
void outputfn (string firstName, string lastName, int totalPoints, int programAverage, int testAverage, int courseAverage, char grade);
string display;
int totalPoints, programAverage, testAverage, courseAverage;
char grade;
ofstream fout;




//Function definitions
int main(){


    //system("color f0");
    headerfn(); 
    getName(firstName,lastName);
    score (firstProgramGrade, secondProgramGrade, thirdProgramGrade, firstTestGrade, secondTestGrade, thirdTestGrade);
    outputfn(firstName, lastName, totalPoints, programAverage, testAverage, courseAverage, grade);


    totalPoints = firstProgramGrade+secondProgramGrade+thirdProgramGrade+firstTestGrade+secondTestGrade+thirdTestGrade;
    programAverage = (firstProgramGrade+secondProgramGrade+thirdProgramGrade) / 3;
    testAverage = (firstTestGrade+secondTestGrade+thirdTestGrade) / 3;
    courseAverage = (programAverage+testAverage) / 2;

    if (courseAverage>=90 && courseAverage<=100)
      grade = 'A';
      else if (courseAverage>=80 && courseAverage<=89)
      grade = 'B';
      else if (courseAverage>=70 && courseAverage<=79)
      grade = 'C';


    system ("pause");
    return 0;
}//end of main

//**********************************************************

void headerfn(void){
   cout<<"012345678901234567890123456789012345678901234567890123456789"<<endl;  
   cout<<"************************************************************"<<endl;
   cout<<"*    IT210 Business Applications with C++                  *"<<endl;
   cout<<"*    Programmer:  Ronnie Bland                             *"<<endl;
   cout<<"*    Date: April 19, 2011                                  *"<<endl;
   cout<<"*                                                          *"<<endl;
   cout<<"*    This program uses functions to read student           *"<<endl;
   cout<<"*    information from the keyboard and outputs             *"<<endl;
   cout<<"*    the results to the monitor and a text file            *"<<endl;                                         
   cout<<"************************************************************"<<endl; 
   cout<<endl;
   cout<<"Welcome to IT 210 Grade Calculator!"<<endl;
   cout<<endl;

   fout<<"012345678901234567890123456789012345678901234567890123456789"<<endl;  
   fout<<"************************************************************"<<endl;
   fout<<"*    IT210 Business Applications with C++                  *"<<endl;
   fout<<"*    Programmer:  Ronnie Bland                             *"<<endl;
   fout<<"*    Date: April 19, 2011                                  *"<<endl;
   fout<<"*                                                          *"<<endl;
   fout<<"*    This program uses functions to read student           *"<<endl;
   fout<<"*    information from the keyboard and outputs             *"<<endl;
   fout<<"*    the results to the monitor and a text file            *"<<endl;                                         
   fout<<"************************************************************"<<endl; 
   fout<<endl;
   fout<<"Welcome to IT 210 Grade Calculator!"<<endl;
   fout<<endl;
}//end of headerfn



void getName (string firstName, string lastName)

{      
     cout<<"Enter your first and last name: ";
     cin>>firstName>>lastName;
     cout<<endl;

     }


int score(int firstProgramGrade, int secondProgramGrade, int thirdProgramGrade, int firstTestGrade, int secondTestGrade, int thirdTestGrade)

{    
   cout<<"Enter the grade for the first program: ";
    cin>>firstProgramGrade;
    cout<<endl;
    cout<<"Enter the grade for the second program: ";
    cin>>secondProgramGrade;
    cout<<endl;
    cout<<"Enter the grade for the third program: ";
    cin>>thirdProgramGrade;
    cout<<endl;
    cout<<"Enter the grade for the first test: ";
    cin>>firstTestGrade;
    cout<<endl;
    cout<<"Enter the grade for the second test: ";
    cin>>secondTestGrade;
    cout<<endl;
    cout<<"Enter the grade for the third test: ";
    cin>>thirdTestGrade;
    cout<<endl;

   return firstProgramGrade, secondProgramGrade, thirdProgramGrade, firstTestGrade, secondTestGrade, thirdTestGrade;

}

void outputfn (string firstName, string lastName, int totalPoints, int programAverage, int testAverage, int courseAverage, char grade) 
{
cout<<"1234567890123456789012345678901234567890123456789012345678901234567890"<<endl;
cout<<"======================================================================"<<endl;


cout <<left << setw(20)<< setfill(' ') << "Student Name" << setw(10) << "Total" 
<<    setw(10) << "Program" << setw(10)<< "Test" << setw(10)<<
    "Course" << setw(10)<< "Grade"<<endl;
   cout<< right <<setfill(' ')<<setw(26)<<"Points"<<
   setw(11)<<"Average"<<setw(10)<<"Average"<<setw(10)<<"Average"<<endl;
cout<<"----------------------------------------------------------------------"<<endl; 


    totalPoints = (firstProgramGrade+secondProgramGrade+thirdProgramGrade+firstTestGrade+secondTestGrade+thirdTestGrade);
    programAverage = (firstProgramGrade+secondProgramGrade+thirdProgramGrade) / 3;
    testAverage = (firstTestGrade+secondTestGrade+thirdTestGrade) / 3;
    courseAverage = (programAverage+testAverage) / 2;
      if (courseAverage>=90 && courseAverage<=100)
      grade = 'A';
      else if (courseAverage>=80 && courseAverage<=89)
      grade = 'B';
      else if (courseAverage>=70 && courseAverage<=79)
      grade = 'C';

    cout<<left<<setw(20)<< setfill(' ')<<firstName+" "+lastName<<setw(10)<<totalPoints<<
    setw(10)<<fixed<<showpoint<<setprecision(2)<<programAverage<<setw(10)<<testAverage<<setw(10)<<courseAverage<<setw(10)<<grade;

cout<<"----------------------------------------------------------------------"<<endl; 

     }    

Edited by Dani: Fixed formatting

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by jonsca
0

Did your instructor go over passing parameters by reference. You need those techniques in this case. For instance, the getName signature would look like:

void getName (string & firstName, string & lastName)

Otherwise, you are just passing in copies of those variables, the changes are being made, and they are lost once the function ends.

Line 119 is plain wrong. A function can only return a single value. Also use the pass by reference technique with those parameters.

Just an aside, you should avoid global variables (except under very specific cases).

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.