View Single Post
Old 05-01-2005, 08:12 AM   #1 (permalink)
unicorn1C
Registered User
 
Join Date: Mar 2005
Posts: 15
unicorn1C is on a distinguished road
help with functions c++

I would appreciate some help with this problem.This program is supose to read students name (i have created the infile) and test scores.
A ) a void function(calculateaverage) to determin the average of 5 test scores use a loop. this function does not output average test score.that is done in main.
B ) a value returning function to determin and return each student grade. function does not output the grade. that is done in main.
i have tried a few different things.
This is what i have:
Code:
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>

using namespace std;

int main()
{
    void calculatescore(double totalscore, ifstream& infile);
    void calculategrade(int grade);
    
    string studentname;
    double totalscore;
    double test1;
    double test2;
    double test3;
    double test4;
    double test5;
    int grade;
    double average;
    ifstream infile;
    ofstream outfile;
    
    infile.open("g://students.txt");
    if (!infile)
    {
        cout << "unable to open files" << endl;
        return 1;
    }
    
     outfile.open("g://stgrades.txt");
     outfile << fixed << showpoint << setprecision(2);
     cout << "Processing data" << endl;
     
     outfile << left << setw(5) << "Student Name"
             << setw(20) << "Test 1"
             << setw(10) << "Test 2"
             << setw(10) << "Test 3"
             << setw(10) << "Test 4"
             << setw(10) << "Test 5"
             << setw(10) << "Average"
             << setw(10) << "Grade" << endl;
             
             
    calculategrade(grade);         
    calculatescore(totalscore, infile);
    average = totalscore / 5;
    if (studentname == studentname)
    do
    {
        infile >> studentname>> test1 >> test2 >> test3 >> test4 >> test5;
        
        outfile << left << setw(10) << studentname
                << setw(25) << test1 
                << setw(15) << test2
                << setw(15) << test3
                << setw(15) << test4
                << setw(10) << test5
                << setw(20) << average
                << setw(15) << grade << endl;
    }
    while (studentname == studentname);
    
        
            
    infile.close();
    outfile.close();

  return 0;
}

                            
                    
    void calculatescore(double totalscore);
     
    infile.open("g://students.text");
    double scores = test1, test2, test3, test4, test5;
     if (scores == scores)
    do
        {
            totalscore = totalscore + scores;
            infile >> test1, test2, test3, test4, test5;
            
             while(scores = test1, test2, test3, test4, test5)
             
            return totalscore;
        }// end while
        
   }        
        
    void calculategrade(int grade);
    
    char a;
    char b;
    char c;
    char d;
    char f;
    
    {
        calculatescore(totalscore);
        average = totalscore / 5
       { 
        if (average >= 90)
            grade = A
        if (average >= 80)
            grage = B
        if (average >= 70)
            grade = c
        if (average >= 60)
            grade = D
        if (average < 60)
            grade = F
        
        return grade;
        }
   }

Last edited by redhead; 05-01-2005 at 09:30 AM. Reason: Remember to use [code ] [/code ] tags
unicorn1C is offline   Reply With Quote