-1

this is my assignment
1) Write a C++ program to calculate the average test scores for 10
students. The test scores are stored in a file named 'scores.dat'.

The average along with the test scores should be written to an
output file named 'results.txt'.

The input file 'scores.dat' contains three columns of integers, total
of 10 lines.

The output file 'results.txt' should contain four columns:

Average Test1 Test2 Test3
_________ _______ _______ _______

*this is what i have

#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;

int main()
{
        int test1, test2, test3, counter;
        ifstream fin;
        ofstream fout;
        fin.open("scores.dat");
        fout.open("results.txt");
        fout << "Average" << setw(4) << "Test1" << setw(4) << "Test2" << setw(4) << "Test3" << endl;
        for(counter = 1; counter <= 10; counter++)
        {
        fin >> test1 >> test2 >> test3;
        fout << ((test1 + test2 + test3)/3) << setw(4)<< test1 <<setw(4) << test2 << setw(4) << test3 << endl;
        }
        return 0;

}

am i on the right track at all? any help would be well appreciated

Edited by Dani: Formatting fixed

Votes + Comments
Use code tags.
2
Contributors
1
Reply
2
Views
12 Years
Discussion Span
Last Post by Narue
1

>am i on the right track at all?
Does it work? If so then you're on the right track, otherwise you're doing something wrong.

Votes + Comments
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.