Reading and printing to a .txt

Hello all, I just joined up :). I am new to C++ and need some assistance.
I am attempting to create a program that reads from a file that looks like this:

Johnson 85 83 77 91 76
Aniston 80 90 95 93 48
Cooper 78 81 11 90 73
Gupta 92 83 30 69 87
Blair 23 45 96 38 59
Clark 60 85 45 39 67
Kennedy 77 31 52 74 83
Bronson 93 94 89 77 97
Sunny 79 85 28 93 82
Smith 85 72 49 75 63

The output(to another file) has to be the individual's 5 sales figures, their name, the average of their 5 figures, and an F-A grade based on their sales.

Rules:
1.) reading from file and averages must be done in a void function.
2.) grading has to be done in a returning function.
3.) all outputs MUST be done in main.
4.) No global variables. No arrays.
5.) The finished output should be a simple grid with headings. 8 columns and 11 rows (counting the row of headings).


Haha I have been at this for a few days now and trying all different things and now i am starting from scratch. I do not want it to be done for me. Just some help with the logic and syntax of making the three functions communicate correctly with one another. And creating an adequate loop system to read the data. Much thanks in advance! :)
Consider posting what you have done so far.
Thank you for responding. :)
Ok, this is where I am at so far, just started from the ground up a few minutes ago.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <string>

using namespace std;

void calcAverage();
char calcGrade(float);

int main(int argc, char *argv[])                                                        
{
    char grade;
    calcAverage();
    
    
    
    
    
    system("PAUSE");
    return EXIT_SUCCESS;
}

void calcAverage()
{
    float t1,t2,t3,t4,t5,avg;
    char grade;
    string name;
    ifstream in;
    ofstream out;
    in.open("data.txt");
    out.open("return.txt");
    int counter=0;
    while(counter<=10)
        {
        in>>name>>t1>>t2>>t3>>t4>>t5;
        avg=(t1+t2+t3+t4+t5)/5;
        counter=counter+1;
        
        
        
        
        }                     
}

char calcGrade(float avg)             
{
    char grade;
    if(avg==100||avg>=90)
    grade='A';
    else if(avg==89||avg>=80)
    grade='B';
    else if(avg==79||avg>=70)
    grade='C';
    else if(avg==69||avg>=60)
    grade='D';
    else if(avg<=59)
    grade='F';
    return grade;                   
}      
Last edited on
Topic archived. No new replies allowed.