Help converting inputs.txt to outputs.txt

Pages: 1234... 7
heres my code now. but all its doing is reading the whole txt file. I need it to create a outputGrades.txt file with the 3 columns of student ID Grade % and Letter grade. any advice ?

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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#include<fstream>
#include<iomanip>
#include<string>
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
    
    string line;
    ifstream sampleGrades("sampleGrades.txt");
    int TotalStudents;
    double ID, Attendance, hw1, hw2, hw3, hw4, hw5, hw6, hw7, exam1, exam2, finalExam;
    float LetterGrade;
    float NumA=0;
    float NumB=0;
    float NumC=0;
    float NumD=0;
    float NumF=0;
    ofstream outputGrades;
    int CourseGradePercentage;
    sampleGrades >> TotalStudents;
    
    ifstream myfile ("samplegrades.txt");
    if (myfile.is_open())
    {
        while ( getline (myfile,line) )
        {
            cout << line << '\n';
        }
        myfile.close();
    }
    
    else cout << "Unable to open file";

    
    for (int i=0; i<TotalStudents; i++)
    {
        sampleGrades >> TotalStudents >> ID >> Attendance >> hw1 >> hw2 >> hw3 >> hw4 >> hw5 >> hw6 >> hw7 >> exam1 >> exam2 >> finalExam;
        
        
        CourseGradePercentage = Attendance*0.10/25 + (hw1 + hw2 + hw3 + hw4 + hw5 + hw6 + hw7)*0.35/700 + exam1*0.15/25 + exam2*0.15/25 + finalExam * 0.25/40;
      
        cout.setf(ios::fixed);
        cout << fixed << setprecision(2) << CourseGradePercentage << endl;
        
        
        {
            if(LetterGrade>=97 && LetterGrade<=100)
            {
                outputGrades<<setw(15)<<" A+ ";
                NumA++;
            }
            else if (LetterGrade>=93 && LetterGrade<97)
            {
                outputGrades<<setw(15)<<" A ";
                NumA++;
            }
            else if (LetterGrade>=90 && LetterGrade<93)
            {
                outputGrades<<setw(15)<<" A- ";
                NumA++;
            }
            else if (LetterGrade>=87 && LetterGrade<90)
            {
                outputGrades<<setw(15)<<" B+ ";
                NumB++;
            }
            else if (LetterGrade>=83 && LetterGrade<87)
            {
                outputGrades<<setw(15)<<" B ";
                NumB++;
            }
            else if (LetterGrade>=80 && LetterGrade<83)
            {
                outputGrades<<setw(15)<<" B- ";
                NumB++;
            }
            else if (LetterGrade>=77 && LetterGrade<80)
            {
                outputGrades<<setw(15)<<" C+ ";
                NumC++;
            }
            else if (LetterGrade>=73 && LetterGrade<77)
            {
                outputGrades<<setw(15)<<" C ";
                NumC++;
            }
            else if (LetterGrade>=70 && LetterGrade<73)
            {
                outputGrades<<setw(15)<<" C- ";
                NumC++;
            }
            else if (LetterGrade>=60 && LetterGrade<70)
            {
                outputGrades<<setw(15)<<" D ";
                NumD++;
            }
            else if (LetterGrade>=0 && LetterGrade<60)
            {
                outputGrades<<setw(15)<<" F ";
                NumF++;
            }
         
        }
        
        outputGrades<<setw(10)<<"ID"<<setw(14)<<"Course Grade"<<setw(14)<<"Letter Grade"<<endl;
        outputGrades<<setw(10)<<ID<<setw(14)<<CourseGradePercentage<<setw(14)<<LetterGrade;
    }
    
    outputGrades<<endl;
    outputGrades<<"The # of A's: "<<NumA<<endl;
    outputGrades<<"The # of B's: "<<NumB<<endl;
    outputGrades<<"The # of C's: "<<NumC<<endl;
    outputGrades<<"The # of D's: "<<NumC<<endl;
    outputGrades<<"The # of F's: "<<NumF<<endl;
    
    sampleGrades.close();
    outputGrades.close();
    return 0;
}
Last edited on
ok so now here is my code and i what it outputs is the whole txt file.. then i have an outputgrades.txt file with my 3 columns which i need and the number of which letter grades so that is better. But there are no numbers calculated under the columns. only the 1 number of like 312000. any advice would be appreciated :)

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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#include<fstream>
#include<iomanip>
#include<string>
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
  
    
    cout.setf(ios::fixed);
    cout.precision(2);
    
    string line;
    string ID;
    string fileName;
    int TotalStudents;
    double Attendance, hw1, hw2, hw3, hw4, hw5, hw6, hw7, exam1, exam2, finalExam;
    char LetterGrade;
    float NumA=0;
    float NumB=0;
    float NumC=0;
    float NumD=0;
    float NumF=0;
    int CourseGradePercentage, i;
    ofstream outputGrades;
    ifstream sampleGrades3("sampleGrades3.txt");
    sampleGrades3 >> TotalStudents;
    
    sampleGrades3.open("sampleGrades3.txt");
    outputGrades.open("OutputGrades3.txt");
    
    cout << "Enter the input file name: ";
    cin >> fileName;
    
    ifstream myfile ("samplegrades3.txt");
    if (myfile.is_open())
    {
        while ( getline (myfile,line) )
        {
            cout << line << '\n';
        }
        myfile.close();
    }
    
    else cout << "Unable to open file";
    
    outputGrades<<"ID"<<setw(14)<<"Course Grade"<<setw(14)<<"Letter Grade"<<endl;
    sampleGrades3 >> ID;
   
   
    for (i=0; i<=TotalStudents; i++)
    {
        
        sampleGrades3 >> ID;
        outputGrades << setw(10) << ID;
       
        outputGrades<<setw(14)<<CourseGradePercentage;
       
        CourseGradePercentage = Attendance*0.10/25 + (hw1 + hw2 + hw3 + hw4 + hw5 + hw6 + hw7)*0.35/700 + exam1*0.15/25 + exam2*0.15/25 + finalExam * 0.25/40;
        
        LetterGrade = CourseGradePercentage;
        outputGrades << setw(14) << " " << LetterGrade << endl;
        
        
        {
            if(LetterGrade>=97 && LetterGrade<=100)
            {
                outputGrades<<setw(15)<<" A+ ";
                NumA++;
            }
            else if (LetterGrade>=93 && LetterGrade<97)
            {
                outputGrades<<setw(15)<<" A ";
                NumA++;
            }
            else if (LetterGrade>=90 && LetterGrade<93)
            {
                outputGrades<<setw(15)<<" A- ";
                NumA++;
            }
            else if (LetterGrade>=87 && LetterGrade<90)
            {
                outputGrades<<setw(15)<<" B+ ";
                NumB++;
            }
            else if (LetterGrade>=83 && LetterGrade<87)
            {
                outputGrades<<setw(15)<<" B ";
                NumB++;
            }
            else if (LetterGrade>=80 && LetterGrade<83)
            {
                outputGrades<<setw(15)<<" B- ";
                NumB++;
            }
            else if (LetterGrade>=77 && LetterGrade<80)
            {
                outputGrades<<setw(15)<<" C+ ";
                NumC++;
            }
            else if (LetterGrade>=73 && LetterGrade<77)
            {
                outputGrades<<setw(15)<<" C ";
                NumC++;
            }
            else if (LetterGrade>=70 && LetterGrade<73)
            {
                outputGrades<<setw(15)<<" C- ";
                NumC++;
            }
            else if (LetterGrade>=60 && LetterGrade<70)
            {
                outputGrades<<setw(15)<<" D ";
                NumD++;
            }
            else if (LetterGrade>=0 && LetterGrade<60)
            {
                outputGrades<<setw(15)<<" F ";
                NumF++;
            }
            
        }
        
        
    }
    
    
    
    outputGrades<<endl<<endl;
    outputGrades<<"The # of A's: "<<NumA<<endl;
    outputGrades<<"The # of B's: "<<NumB<<endl;
    outputGrades<<"The # of C's: "<<NumC<<endl;
    outputGrades<<"The # of D's: "<<NumC<<endl;
    outputGrades<<"The # of F's: "<<NumF<<endl;
    
    return 0;
}
Last edited on
can anyone help please ?
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
61
62
63
64
65
66
67
#include <iostream>
#include <string>
#include <fstream>

const int NHOMEWORK = 7 ;

std::istream& read_hw_scores( std::istream& stm, double hw[NHOMEWORK] )
{
   for( int i = 0 ; i < NHOMEWORK ; ++i ) stm >> hw[i] ;
   return stm ;
}

std::string score_to_grade( double score )
{
    if( score > 100 ) return "F " ;

    else if( score > 96 ) return "A+" ;
    else if( score > 92 ) return "A " ;
    else if( score > 89 ) return "A-" ;

    else if( score > 86 ) return "B+" ;
    else if( score > 82 ) return "B " ;
    else if( score > 79 ) return "B-" ;

    else if( score > 76 ) return "C+" ;
    else if( score > 72 ) return "C " ;
    else if( score > 69 ) return "C-" ;

    else if( score > 59 ) return "D " ;

    else return "F " ;
}



int main()
{
    std::ifstream fin( "sampleGrades3.txt" );
    std::ifstream fout( "OutputGrades3.txt" );
    // TODO: verify that files have been opened

    int id ;
    double attendance, exam1, exam2, final_exam;
    double hw[NHOMEWORK] ;

    int num_A = 0, num_B = 0, num_C = 0, num_D = 0, num_F = 0 ;

    while( fin >> id >> attendance && read_hw_scores( fin, hw ) && fin >> exam1 >> exam2 >> final_exam )
    {
        double hw_total = 0 ;
        for( double s : hw ) hw_total += s ;

        const double grade_percent = attendance * 0.10/25 + hw_total * 0.35/700 + (exam1+exam2) * 0.15/25 + final_exam * 0.25/40 ;
        const std::string grade = score_to_grade(grade_percent) ;

        if( grade[0] == 'A' ) ++num_A ;
        else if( grade[0] == 'B' ) ++num_B ;
        else if( grade[0] == 'C' ) ++num_C ;
        else if( grade[0] == 'D' ) ++num_D ;
        else ++num_F ;

        // TODO: write record to output file
    }

    // TODO: write totals (numA etc.) to output file

}
wow JL you are such a good dude ! thank you :) a couple questions.
what im supposed to do is to have 3 columns:
--> ID | Grade(%) | Letter Grade

- That ^ is supposed to be in an outputGrades.txt file.

ThenI have to have my program output *in xcode (to the screen)* these columns:

--> Letter Grade | Count of said letter | Attendance %

-So i just want my program to output my first 3 columns to an output.txt file then ill try and figure out the 2nd part.
-But when you say write record to output file what do you mean by that ??
do you mean this ?
1
2
3
4
5
6
outputGrades<<setw(14)<<CourseGradePercentage;
        
        CourseGradePercentage = Attendance*0.10/25 + (hw1 + hw2 + hw3 + hw4 + hw5 + hw6 + hw7)*0.35/700 + exam1*0.15/25 + exam2*0.15/25 + finalExam * 0.25/40;
        
        LetterGrade = CourseGradePercentage;
        outputGrades << setw(14) << " " << LetterGrade << endl;


-and when you say write totals , you are saying to go through all 137 lines of my txt input file and calculate it myself ? sorry maybe i am misunderstanding. Than you JL. im learning as we speak
so i have this now and the build succeeded but there was no outputGrades4.txt in my debug directory where it should be
-here is code. is this what you suggested i do?
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#include <iostream>
#include <string>
#include <fstream>
#include <cmath>
#include <iomanip>

using namespace std;

const int NHOMEWORK = 7 ;

std::istream& read_hw_scores( std::istream& stm, double hw[NHOMEWORK] )
{
    for( int i = 0 ; i < NHOMEWORK ; ++i ) stm >> hw[i] ;
    return stm ;
}

std::string score_to_grade( double score )
{
    if( score > 100 ) return "F " ;
    
    else if( score > 96 ) return "A+" ;
    else if( score > 92 ) return "A " ;
    else if( score > 89 ) return "A-" ;
    
    else if( score > 86 ) return "B+" ;
    else if( score > 82 ) return "B " ;
    else if( score > 79 ) return "B-" ;
    
    else if( score > 76 ) return "C+" ;
    else if( score > 72 ) return "C " ;
    else if( score > 69 ) return "C-" ;
    
    else if( score > 59 ) return "D " ;
    
    else return "F " ;
}

string line, filename, myfile;;


int main()
{
    cout.setf(ios::fixed);
    cout.precision(2);
    
    std::ifstream fin( "sampleGrades4.txt" );
    std::ifstream fout( "OutputGrades4.txt" );
    
    ifstream myfile ("samplegrades4.txt");
    
    if (myfile.is_open())
    {
        while ( getline (myfile,line) )
        {
            cout << line << '\n';
        }
        myfile.close();
    }
    
    else cout << "Unable to open file";
    
    int id ;
    double attendance, exam1, exam2, final_exam;
    double hw[NHOMEWORK] ;
    ifstream sampleGrades4("sampleGrades4.txt");
    ofstream outputGrades;
    
    int num_A = 0, num_B = 0, num_C = 0, num_D = 0, num_F = 0 ;
    
    while( fin >> id >> attendance && read_hw_scores( fin, hw ) && fin >> exam1 >> exam2 >> final_exam )
    {
        double hw_total = 0 ;
        for( double s : hw ) hw_total += s ;
        
        const double grade_percent = attendance * 0.10/25 + hw_total * 0.35/700 + (exam1+exam2) * 0.15/25 + final_exam * 0.25/40 ;
        const std::string grade = score_to_grade(grade_percent) ;
        
        if( grade[0] == 'A' ) ++num_A ;
        else if( grade[0] == 'B' ) ++num_B ;
        else if( grade[0] == 'C' ) ++num_C ;
        else if( grade[0] == 'D' ) ++num_D ;
        else ++num_F ;
        
        outputGrades<<"ID"<<setw(14)<<"Course Grade"<<setw(14)<<"Letter Grade"<<endl;
        outputGrades << setw(10) << id;
        
        outputGrades << setw(14) << grade_percent;
        
        outputGrades << setw(14) << " " << grade << endl;
        
        // TODO: write record to output file
    }
   
    
    outputGrades << "A's" << num_A;
    outputGrades << "B's" << num_B;
    outputGrades << "C's" << num_C;
    outputGrades << "D's" << num_D;
    outputGrades << "F's" << num_F;
    
    // TODO: write totals (numA etc.) to output file
    
}
that^ program keeps threading to mumbo jumbo when i run it.. lol so frustrating !!!
closed account (48T7M4Gy)
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#include<fstream>
#include<iomanip>
#include<string>
#include<iostream>
#include<cmath>

using namespace std;

int main()
{
	ifstream sampleGrades("sampleGrades.txt");
	ofstream outputGrades("outputgrades.txt");

	string firstLine;
	int TotalStudents;

	double ID, Attendance, hw1, hw2, hw3, hw4, hw5, hw6, hw7, exam1, exam2, finalExam;

	float LetterGrade;

	int NumA = 0;
	int NumB = 0;
	int NumC = 0;
	int NumD = 0;
	int NumF = 0;

	int CourseGradePercentage = 0;
	string Grade = "";

	if (sampleGrades.is_open())
	{
		getline(sampleGrades, firstLine);

		sampleGrades >> TotalStudents;
		cout << "No. of students: " << TotalStudents << endl;

		cout << firstLine << endl;
		cout << "ID" << setw(14) << "Course Grade" << setw(14) << "Letter Grade" << endl;
		outputGrades << "ID" << setw(14) << "Course Grade" << setw(14) << "Letter Grade" << endl;

		while ( !sampleGrades.eof() )
		{
			sampleGrades >> ID >> Attendance >> hw1 >> hw2 >> hw3 >> hw4 >> hw5 >> hw6 >> hw7 >> exam1 >> exam2 >> finalExam;
			cout << ID << '\t' << Attendance << '\t';
			outputGrades << ID << '\t' << Attendance << '\t';

			LetterGrade = Attendance*0.10 / 25 + (hw1 + hw2 + hw3 + hw4 + hw5 + hw6 + hw7)*0.35 / 700 + exam1*0.15 / 25 + exam2*0.15 / 25 + finalExam * 0.25 / 40;
			if (LetterGrade >= 97 && LetterGrade <= 100)
			{
				Grade = " A+ ";
				NumA++;
			}
			else if (LetterGrade >= 93 && LetterGrade < 97)
			{
				Grade = " A ";
				NumA++;
			}
			else if (LetterGrade >= 90 && LetterGrade < 93)
			{
				Grade = " A- ";
				NumA++;
			}
			else if (LetterGrade >= 87 && LetterGrade < 90)
			{
				Grade = " B+ ";
				NumB++;
			}
			else if (LetterGrade >= 83 && LetterGrade < 87)
			{
				Grade = " B ";
				NumB++;
			}
			else if (LetterGrade >= 80 && LetterGrade < 83)
			{
				Grade = " B- ";
				NumB++;
			}
			else if (LetterGrade >= 77 && LetterGrade < 80)
			{
				Grade = " C+ ";
				NumC++;
			}
			else if (LetterGrade >= 73 && LetterGrade < 77)
			{
				Grade = " C ";
				NumC++;
			}
			else if (LetterGrade >= 70 && LetterGrade < 73)
			{
				Grade = " C- ";
				NumC++;
			}
			else if (LetterGrade >= 60 && LetterGrade < 70)
			{
				Grade = " D ";
				NumD++;
			}
			else if (LetterGrade >= 0 && LetterGrade < 60)
			{
				Grade = " F ";
				NumF++;
			}
			cout << setw(15) << Grade << endl;
			outputGrades << setw(15) << Grade << endl;
		}
		
		outputGrades << setw(10) << ID << setw(14) << CourseGradePercentage << setw(14) << LetterGrade << endl;
		outputGrades << endl;
		outputGrades << "The # of A's: " << NumA << endl;
		outputGrades << "The # of B's: " << NumB << endl;
		outputGrades << "The # of C's: " << NumC << endl;
		outputGrades << "The # of D's: " << NumC << endl;
		outputGrades << "The # of F's: " << NumF << endl;

		sampleGrades.close();
		outputGrades.close();
	}
	else
		cout << "Unable to open file";

	return 0;
}
hey kemort ! thank you
this is what i got when i used that code for the first 30 lines. the course grade numbers are actually there attendance
ID  Course Grade  Letter Grade
1	9	             F 
2	8	             F 
3	24	             F 
4	25	             F 
5	21	             F 
6	24	             F 
7	17	             F 
8	25	             F 
9	23	             F 
10	24	             F 
11	22	             F 
12	23	             F 
13	11	             F 
14	24	             F 
15	23	             F 
16	23	             F 
17	23	             F 
18	22	             F 
19	7	             F 
20	24	             F 
Last edited on
closed account (48T7M4Gy)
All you have to do is complete the list of your variables at line 44 and it will read and process the data completely including output if you track it through. I changed line 47 to LetterGrade simply to get output. Just change it back to what you had originally.

As far as headings are concerned all you do is modify line 38. And if you get rid of the setw,s on that line and just type out the heading in full you'll find it easier.

Last edited on
i did that and it got this as a sample
No. of students: 137
ID Attendance hw1 hw2 hw3 hw4 hw5 hw6 hw7 exam1 exam2 finalExam
ID  Course Grade  Letter Grade
199879100100850100242432             F 
28105105000002300             F 
32410595105100969897252537             F 
42598.7105105105103.95104105222139             F 
52194.5989295909090.3201530             F 
62495.55100991009260105242132             F 
71790958290.3689960231425             F 
82590102.998.795.551007210521233


here is the code that i have now
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#include<fstream>
#include<iomanip>
#include<string>
#include<iostream>
#include<cmath>

using namespace std;

int main()
{
    ifstream sampleGrades4("sampleGrades4.txt");
    ofstream outputGrades("outputgrades.txt");
    
    string firstLine;
    int TotalStudents;
    
    double ID, Attendance, hw1, hw2, hw3, hw4, hw5, hw6, hw7, exam1, exam2, finalExam;
    
    float LetterGrade;
    
    int NumA = 0;
    int NumB = 0;
    int NumC = 0;
    int NumD = 0;
    int NumF = 0;
    
    int CourseGradePercentage = 0;
    string Grade = "";
    
    if (sampleGrades4.is_open())
    {
        getline(sampleGrades4, firstLine);
        
        sampleGrades4 >> TotalStudents;
        cout << "No. of students: " << TotalStudents << endl;
        
        cout << firstLine << endl;
        cout << "ID" << setw(14) << "Course Grade" << setw(14) << "Letter Grade" << endl;
        outputGrades << "ID" << setw(14) << "Course Grade" << setw(14) << "Letter Grade" << endl;
        
        while ( !sampleGrades4.eof() )
        {
            sampleGrades4 >> ID >> Attendance >> hw1 >> hw2 >> hw3 >> hw4 >> hw5 >> hw6 >> hw7 >> exam1 >> exam2 >> finalExam;
            cout << ID << Attendance << hw1 << hw2 << hw3 << hw4 << hw5 << hw6 << hw7 << exam1 << exam2 << finalExam;
            outputGrades << ID << Attendance << hw1 << hw2 << hw3 << hw4 << hw5 << hw6 << hw7 << exam1 << exam2 << finalExam;
            
            CourseGradePercentage = Attendance*0.10 / 25 + (hw1 + hw2 + hw3 + hw4 + hw5 + hw6 + hw7)*0.35 / 700 + exam1*0.15 / 25 + exam2*0.15 / 25 + finalExam * 0.25 / 40;
            if (LetterGrade >= 97 && LetterGrade <= 100)
            {
                Grade = " A+ ";
                NumA++;
            }
            else if (LetterGrade >= 93 && LetterGrade < 97)
            {
                Grade = " A ";
                NumA++;
            }
            else if (LetterGrade >= 90 && LetterGrade < 93)
            {
                Grade = " A- ";
                NumA++;
            }
            else if (LetterGrade >= 87 && LetterGrade < 90)
            {
                Grade = " B+ ";
                NumB++;
            }
            else if (LetterGrade >= 83 && LetterGrade < 87)
            {
                Grade = " B ";
                NumB++;
            }
            else if (LetterGrade >= 80 && LetterGrade < 83)
            {
                Grade = " B- ";
                NumB++;
            }
            else if (LetterGrade >= 77 && LetterGrade < 80)
            {
                Grade = " C+ ";
                NumC++;
            }
            else if (LetterGrade >= 73 && LetterGrade < 77)
            {
                Grade = " C ";
                NumC++;
            }
            else if (LetterGrade >= 70 && LetterGrade < 73)
            {
                Grade = " C- ";
                NumC++;
            }
            else if (LetterGrade >= 60 && LetterGrade < 70)
            {
                Grade = " D ";
                NumD++;
            }
            else if (LetterGrade >= 0 && LetterGrade < 60)
            {
                Grade = " F ";
                NumF++;
            }
            cout << setw(15) << Grade << endl;
            outputGrades << setw(15) << Grade << endl;
        }
        
        outputGrades << setw(10) << ID << setw(14) << CourseGradePercentage << setw(14) << LetterGrade << endl;
        outputGrades << endl;
        outputGrades << "The # of A's: " << NumA << endl;
        outputGrades << "The # of B's: " << NumB << endl;
        outputGrades << "The # of C's: " << NumC << endl;
        outputGrades << "The # of D's: " << NumC << endl;
        outputGrades << "The # of F's: " << NumF << endl;
        
        sampleGrades4.close();
        outputGrades.close();
    }
    else
        cout << "Unable to open file";
    
    return 0;
}
closed account (48T7M4Gy)
you have to put additional formatting spaces, setw's whatever in line 44

(it doesn't happen automatically) The important thing is just to put a space between the items at this stage and make sure the data is being read correctly. I know it is, but you need to convince yourself
o ya i meant to add the setw's thanks . lol i do need to convince myself. But that letter grades arent working. it says they are all F's
also i only want the ID Grade(%) & Letter Grade outputted. i think it looks so crazy becaue all 7 hw's midterms and final are on the output txt . but if i add CourseGradePercentage to the cout and output it doesnt calculate right :(
ya its not actually calculating my inputfile values into the % and letter grade in my output for some reason
closed account (48T7M4Gy)
all that means is your equation is wrong. The file records are being read properly as far as I can see.

just make a dummy equation and add them all up. that way you can quickly check a number is not accidentally a string. Coursegrade was the reason I changed it arbitrarily to LetterGrade because it didn't make sense at the time.
here is my code now. i need the percentage at a setprecision(2) but for some reason its applying it to my ID

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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#include<fstream>
#include<iomanip>
#include<string>
#include<iostream>
#include<cmath>

using namespace std;

int main()
{
    
    ifstream sampleGrades4("sampleGrades4.txt");
    ofstream outputGrades("outputgrades.txt");
    
    string firstLine;
    int TotalStudents;
    
    double ID = 0.0, Attendance = 0.0, hw1, hw2, hw3, hw4, hw5, hw6, hw7, exam1, exam2, finalExam;
    
    float LetterGrade;
    
    int NumA = 0;
    int NumB = 0;
    int NumC = 0;
    int NumD = 0;
    int NumF = 0;
    
    int CourseGradePercentage = 0;
    string Grade = "";
    
    if (sampleGrades4.is_open())
    {
        getline(sampleGrades4, firstLine);
        
        sampleGrades4 >> TotalStudents;
        cout << "No. of students: " << TotalStudents << endl;
        
        cout << firstLine << endl;
        cout << "ID" << setw(14) << "Course Grade" << setw(14) << "Letter Grade" << endl;
        outputGrades << "ID" << setw(14) << "Course Grade" << setw(14) << "Letter Grade" << endl;
        
        while ( !sampleGrades4.eof() )
        {
            sampleGrades4 >> ID >> Attendance >> hw1 >> hw2 >> hw3 >> hw4 >> hw5 >> hw6 >> hw7 >> exam1 >> exam2 >> finalExam;
            cout << ID << setw(14) << setw(14) << LetterGrade;
            cout << fixed << setprecision(2) << CourseGradePercentage;
            outputGrades << ID << setw(14) << CourseGradePercentage << setw(14) << LetterGrade;
            
            CourseGradePercentage = Attendance*0.10 / 25 + (hw1 + hw2 + hw3 + hw4 + hw5 + hw6 + hw7)*0.35 / 700 + exam1*0.15 / 25 + exam2*0.15 / 25 + finalExam * 0.25 / 40;
            if (LetterGrade >= 97 && LetterGrade <= 100)
            {
                Grade = " A+ ";
                NumA++;
            }
            else if (LetterGrade >= 93 && LetterGrade < 97)
            {
                Grade = " A ";
                NumA++;
            }
            else if (LetterGrade >= 90 && LetterGrade < 93)
            {
                Grade = " A- ";
                NumA++;
            }
            else if (LetterGrade >= 87 && LetterGrade < 90)
            {
                Grade = " B+ ";
                NumB++;
            }
            else if (LetterGrade >= 83 && LetterGrade < 87)
            {
                Grade = " B ";
                NumB++;
            }
            else if (LetterGrade >= 80 && LetterGrade < 83)
            {
                Grade = " B- ";
                NumB++;
            }
            else if (LetterGrade >= 77 && LetterGrade < 80)
            {
                Grade = " C+ ";
                NumC++;
            }
            else if (LetterGrade >= 73 && LetterGrade < 77)
            {
                Grade = " C ";
                NumC++;
            }
            else if (LetterGrade >= 70 && LetterGrade < 73)
            {
                Grade = " C- ";
                NumC++;
            }
            else if (LetterGrade >= 60 && LetterGrade < 70)
            {
                Grade = " D ";
                NumD++;
            }
            else if (LetterGrade >= 0 && LetterGrade < 60)
            {
                Grade = " F ";
                NumF++;
            }
            cout << setw(15) << Grade << endl;
            outputGrades << setw(15) << Grade << endl;
        }
        
        outputGrades << ID << setw(14);
        outputGrades << fixed << setprecision(2) << CourseGradePercentage;
        outputGrades << setw(14) << LetterGrade;
        outputGrades << endl;
        outputGrades << "The # of A's: " << NumA << endl;
        outputGrades << "The # of B's: " << NumB << endl;
        outputGrades << "The # of C's: " << NumC << endl;
        outputGrades << "The # of D's: " << NumC << endl;
        outputGrades << "The # of F's: " << NumF << endl;
        
        sampleGrades4.close();
        outputGrades.close();
    }
    else
        cout << "Unable to open file";
    
    return 0;
}
closed account (48T7M4Gy)
line 47 refers to Coursegrade
lines 48 on refer to LetterGrade

That was the reason I changed line 47. Coursegrade wasn't being used!
o so your saying CourseGradePercentage isnt being used ?? hmm.. on my homework assignment this is what my teacher wrote

The numerical grade is calculated as:
CourseGradePercentage = Attendance*0.10/25 + (hw1 + hw2 + hw3 + hw4 + hw5 + hw6 + hw7)*0.35/700 + exam1*0.15/25 + exam2*0.15/25 + finalExam * 0.25/40

ugh i just did this and now its giving me the ID number with a 0 in front of the numbers

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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#include<fstream>
#include<iomanip>
#include<string>
#include<iostream>
#include<cmath>

using namespace std;

int main()
{
    ifstream sampleGrades4("sampleGrades4.txt");
    ofstream outputGrades("outputgrades.txt");
    
    string firstLine;
    int TotalStudents;
    
    double ID, Attendance, hw1, hw2, hw3, hw4, hw5, hw6, hw7, exam1, exam2, finalExam;
    
    float LetterGrade;
    
    int NumA = 0;
    int NumB = 0;
    int NumC = 0;
    int NumD = 0;
    int NumF = 0;
    
    int CourseGradePercentage = 0;
    string Grade = "";
    
    if (sampleGrades4.is_open())
    {
        getline(sampleGrades4, firstLine);
        
        sampleGrades4 >> TotalStudents;
        cout << "No. of students: " << TotalStudents << endl;
        
        cout << firstLine << endl;
        cout << "ID" << setw(14) << "Course Grade" << setw(14) << "Letter Grade" << endl;
        outputGrades << "ID" << setw(14) << "Course Grade" << setw(14) << "Letter Grade" << endl;
        
        while ( !sampleGrades4.eof() )
        {
            sampleGrades4 >> ID >> Attendance >> hw1 >> hw2 >> hw3 >> hw4 >> hw5 >> hw6 >> hw7 >> exam1 >> exam2 >> finalExam;
      
            
            CourseGradePercentage = Attendance*0.10 / 25 + (hw1 + hw2 + hw3 + hw4 + hw5 + hw6 + hw7)*0.35 / 700 + exam1*0.15 / 25 + exam2*0.15 / 25 + finalExam * 0.25 / 40;
            
            cout << ID << setw(14) << CourseGradePercentage;
            outputGrades << ID << setw(14) << CourseGradePercentage;
            
            if (LetterGrade >= 97 && LetterGrade <= 100)
            {
                Grade = " A+ ";
                NumA++;
            }
            else if (LetterGrade >= 93 && LetterGrade < 97)
            {
                Grade = " A ";
                NumA++;
            }
            else if (LetterGrade >= 90 && LetterGrade < 93)
            {
                Grade = " A- ";
                NumA++;
            }
            else if (LetterGrade >= 87 && LetterGrade < 90)
            {
                Grade = " B+ ";
                NumB++;
            }
            else if (LetterGrade >= 83 && LetterGrade < 87)
            {
                Grade = " B ";
                NumB++;
            }
            else if (LetterGrade >= 80 && LetterGrade < 83)
            {
                Grade = " B- ";
                NumB++;
            }
            else if (LetterGrade >= 77 && LetterGrade < 80)
            {
                Grade = " C+ ";
                NumC++;
            }
            else if (LetterGrade >= 73 && LetterGrade < 77)
            {
                Grade = " C ";
                NumC++;
            }
            else if (LetterGrade >= 70 && LetterGrade < 73)
            {
                Grade = " C- ";
                NumC++;
            }
            else if (LetterGrade >= 60 && LetterGrade < 70)
            {
                Grade = " D ";
                NumD++;
            }
            else if (LetterGrade >= 0 && LetterGrade < 60)
            {
                Grade = " F ";
                NumF++;
            }
            cout << setw(15) << Grade << endl;
            outputGrades << setw(15) << Grade << endl;
        }
        
        outputGrades << setw(10) << ID << setw(14) << CourseGradePercentage << setw(14) << LetterGrade << endl;
        outputGrades << endl;
        outputGrades << "The # of A's: " << NumA << endl;
        outputGrades << "The # of B's: " << NumB << endl;
        outputGrades << "The # of C's: " << NumC << endl;
        outputGrades << "The # of D's: " << NumC << endl;
        outputGrades << "The # of F's: " << NumF << endl;
        
        sampleGrades4.close();
        outputGrades.close();
    }
    else
        cout << "Unable to open file";
    
    return 0;
}
Last edited on
ive been playing around with it and moving stuff but it just doesnt want to give me a percent (75.20 as an example) and all are F's . im sorry kemort i know you are trying to push me into the right direction. im trying though i promise
Pages: 1234... 7