Assign letter grades with array

Hello everyone. I've been assigned an array to generate letter grades from a points score. I believe I've laid out the array in the proper way but when it comes down the table to generate the letter grades I cant seem to make it output anything but ">N". Its late for me atleast and I would love if someone would be kind enough to poke me in the eye with what I'm missing.

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
#include <stdio.h>
#define MAX_ENTRIES 50
#include <iostream>

using namespace std;
int main (void)
{
    int student_name[MAX_ENTRIES];
    int test_score[MAX_ENTRIES];
    int grade_count[MAX_ENTRIES];
    int count = 0;
    int sum,i,high_stud_name, A = 0, B = 0, C = 0, D = 0, F = 0;
    char char_val;
    char grade[5];

        cout << "This is a program\n";
        cout << "It will generate a letter grade from points\n";
        cout << "All grades are generated from 100 point scores\n";
        cout << "Scores of Zeros aren't allowed\n";
        cout << "When prompted please input student names and points\n";
        cout << "And when finished, Input zero and it will assign letter grades\n";

    while (count < MAX_ENTRIES && student_name[count] != 0)
    {

        cout << ("Enter one of your student's name: ");
        scanf("%i", &student_name[count]);
            if ( student_name[count] == 0 )
                break;
        cout << ("Enter the student's test score: ");
        scanf("%i", &test_score[count]);
        ++count;
    }

    for ( i=0; i<=count; ++i )
    {
        if ( test_score[i] >= 90 )
            grade_count[i] = 'A';
        else if ( test_score[i] >= 80 )
            grade_count[i] = 'B';
        else if ( test_score[i] >= 70 )
            grade_count[i] = 'C';
        else if ( test_score[i] >= 60 )
            grade_count[i] = 'D';
        else if (test_score[i] <= 59 )
            grade_count[i] = 'F';
    }


    sum = 0;
    sum += test_score[count];


    cout << ("\nStudent ID Test Score Letter Grade\n");
    cout << ("---------- ---------- ------------\n");
    for (i = 0; i<count; ++i)
        cout << (student_name[i], test_score[i],  grade[i]);


    return 0;
}


Thank you for any help and POKE HARD.
And FYI Im probably stupid or blind at this point.
Last edited on
I see a problem at line 57: cout << (student_name[i], test_score[i], grade[i]);

You need to output the vars separately, like so:
cout << setw(10) << student_name[i] << '\t' << test_score[i] << '\t' << grade_count[i] << endl;
@mhurt

I notice you're assigning a char, to an int array.
1
2
3
4
5
6
7
8
9
10
if ( test_score[i] >= 90 )
            grade_count[i] = 'A'; //grade_count is an int array
        else if ( test_score[i] >= 80 )
            grade_count[i] = 'B';
        else if ( test_score[i] >= 70 )
            grade_count[i] = 'C';
        else if ( test_score[i] >= 60 )
            grade_count[i] = 'D';
        else if (test_score[i] <= 59 )
            grade_count[i] = 'F';


And you're checking a char array input for an int.
 
 if ( student_name[count] == 0 )


Neither one should work out to well.

Here's an updated version of your program. If you have questions on it, please ask.

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
#include <stdio.h>
#include <iostream>
#include <string>

#define MAX_ENTRIES 50

using std::cout;
using std::cin;
using std::endl;
using std::string;

int main()
{
	string student_name[MAX_ENTRIES];
	int test_score[MAX_ENTRIES];
	char grade_score[MAX_ENTRIES];
	int count = 0;
	int sum = 0, i, high_stud_name;
	double average;

	char letter_grade[5] = {'A','B','C','D','F'};
	int grade[5] = { 90, 80, 70, 60, 0 };

	cout << "This is a grading program" << endl;
	cout << "It will generate a letter grade from points." << endl;
	cout << "All grades are generated from 100 point scores." << endl;
	cout << "When prompted please input student names and points" << endl;
	cout << "and when finished, input a zero as a name, and it will assign letter grades" << endl << endl;

	do
	{
		cout << "Enter one of your student's name: " << endl;
		cin >> student_name[count];
		if (student_name[count] != "0")
		{
			cout << "Enter the student's test score: " << endl;
			do{
				cin >> test_score[count];
				if (test_score[count] > 100) // Check if scores are out of input ranges
					cout << "Test scores can NOT exceed 100. Re-enter test score." << endl;
				if (test_score[count] < 0)
					cout << "Test scores can NOT be less than zero. Re-enter test score." << endl;
			} while (test_score[count] < 0 || test_score[count] > 100);
			sum += test_score[count]; // Increase sum
			count++; // Increase count
		}
	}while (count < MAX_ENTRIES && student_name[count] != "0");

	for (i = 0; i < count; i++)
	{
		for (int x = 0; x < 5; x++)
		{
			if (test_score[i] >= grade[x])
			{
				grade_score[i] = letter_grade[x]; // Found grade and assigned letter
				x = 5; // So, exit the x loop
			}
		}
	}


	cout << endl << "Student ID\tTest Score\tLetter Grade" << endl;
	cout << "----------\t----------\t------------" << endl;
	for (i = 0; i<count; ++i)
		cout << student_name[i] << "\t\t" << test_score[i] << "\t\t" << grade_score[i] << endl;

	return 0;
}
Last edited on
Thank you whitenite and Thomas for all your help. Whitenite I was actually getting that warning when I was messing with the program myself. I wasnt sure how to precede with a modification but thank you for showing me how.
Topic archived. No new replies allowed.