enumerated data type help

Hello, I am brand new to enumerated data type and this is my first effort at this type of programming. The program description is: to write a program to convert the number of completed credits for all Undergraduate students to class levels, and to make the data searchable by student ID number.

The text file looks like:
CC333333 U 3
AA111111 G 36
BB222222 U 80
DD444444 U 52
CD334455 U 100
BC223344 U 10
AB112233 A 134
EE555555 G 18
DE445566 U 122

student ID: AA111111
Student status: U
Students number of completed courses: 3

I need to create an enumerated type that has the class levels as its values, in the order given, so that the ordinal value of FRESHMAN will be 0, and the ordinal value of SENIOR will be 3. The table is as follows:

Credits Completed Class Level
Under 32 Freshman
32 – 63 Sophomore
64 - 95 Junior
Over 95 Senior
I need to store the enumerated type value in the second array, not the ordinal integer value.

ISSUE:
The program complies and runs. It also stores the students ID with a status of "U" in the correct array. When I debug, the function studentNum reads in the correct completed courses but it outputs Senior instead of Freshman. I'm not sure what's going on. If someone could point me in the right direction I would greatly appreciate that. Thank you.

Here is my code:
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
139
140
141
142
143
144
145
146
  #include <iostream>
#include <string>
#include <fstream>
#include <iomanip>
using namespace std;

// declare enumerated type globally
enum studentLevel {FRESHMAN, SOPHOMORE, JUNIOR, SENIOR}; 

// Global constants
const int MAX_ARRAY = 3;
const string IN_CREDIT_FILE  = "CREDITS.txt";
const string OUT_CREDIT_FILE = "OUT_CREDITS.txt";

// prototypes
void display_header();
void readCreditFile (ifstream&, string [], string [], int&);	
studentLevel studentNum (int);
string studentTitle (studentLevel);
double highestExpense ();
double aboveAverageExpense ();
void displayExpenses ();

//*************************************************************************
//  FUNCTION:	  main
//  DESCRIPTION:  Asks user for a base number, then calls functions to read 
//                an exponent and compute the base raised to the exponent, and  
//                then displays the results.  Loops, requesting numbers until 
//                user enters zero for base.
//  OUTPUT:       Return Value:  0 on success
//  CALLS TO:	  GetPositiveNum, CalcAnswer
//************************************************************************* 
int main()	
{
	//VARIABLES
	int cnt = 0;								// counter used for employee coverage
	int cnt1;
	double empAverage;							// return value from the called function averageExpense for employee average
	double famAverage;  						// return value from the called function averageExpense for family average
	double empHighest;							// return value from the called function highestExpense for employee average
	double famHighest;							// return value from the called function highestExpense for family average
	double empAbove;							// return value from the called function aboveAverageExpense for employee average
	double famAbove;							// return value from the called function aboveAverageExpense for family average
	// opening the text file medical.txt
	ifstream inCreditData;						
	inCreditData.open(IN_CREDIT_FILE.c_str());
	
	// array's
	string idNum [MAX_ARRAY];
	string classLevel [MAX_ARRAY];
	
  	// verification that file exists 
    if (!inCreditData)
    {	   
       cout << "The input data file does not exist!" << endl;
       cout << "Please verify input file and run the program again!" << endl;
       return 5;
    }
	// calling different functions to compute and display the results   	
	else
	{
		cout << "File opened successfully! Reading file." << endl << endl;
		readCreditFile (inCreditData, idNum, classLevel, cnt);
		
	}	
	return 0;
}
//*************************************************************************
//  FUNCTION:	 readCreditFile
//  DESCRIPTION: reads data from a text file into two arrays called fam[] 
//				 and emp[]. Data is transfered into  
//*************************************************************************
void readCreditFile (ifstream& inCreditData, string idNum [], string classLevel [], int& cnt)
{
	string studentId;					// stored value for the students ID number
	char ch;							// stored value for the students status
	int classesTaken;					// number of credits completed by student
	studentLevel num;					// the numerical value of the function studentClass;
	string title;						// stored value from the function studentClass
	bool arrayFull = false;			    // check to see if there is still space in the array idNum[]
	
	while(inCreditData && cnt <= MAX_ARRAY)
	{
		inCreditData >> studentId >> ch >> classesTaken;
		if (ch == 'U' && !arrayFull)
		{
			idNum[cnt] = studentId;
			num = studentNum (classesTaken);	// beginning of the enum
			title = studentTitle (num);
			classLevel[cnt] = title;
			cnt++;
			if (cnt >= MAX_ARRAY)
			{
				arrayFull = true;
				cout << "Error: only the first " << MAX_ARRAY
				     << " students will be read." << endl << endl;
			}
		}
		
	}
	
	inCreditData.close();
 	
    return;
}
//*************************************************************************
//  FUNCTION:	 studentClass
//  DESCRIPTION: reads data from a text file into two arrays called fam[] 
//*************************************************************************
studentLevel studentNum (int numCredits)
{
	studentLevel title;
	
	if(numCredits < 32)
		studentLevel title = FRESHMAN;
	else if (numCredits >= 32 && numCredits <= 63)
		studentLevel title = SOPHOMORE;
	else if (numCredits >= 64 && numCredits <= 95)
		studentLevel title = JUNIOR;
	else 
		studentLevel title = SENIOR;

			
	return title;
}
//***************************************************************************
string studentTitle (studentLevel level)
{
	string name;
	switch (level)
	{
		case 0: 
			name = "Freshman";
			break;
		case 1:
			name = "Sophomore";
			break;
		case 2:
			name = "Junior";
			break;
		case 3:
			name = "Senior";			
	}
		
   return name;
}
studentLevel title = FRESHMAN; on line 115 (117,119,121) declares a new variable; this variable has the same name as the variable declared on line 112 .
The name in the nested scope hides the name in the outer scope.
On line 124, what is returned is the (uninitialised and unassigned) title declared on line 112.

Either:
1
2
3
4
5
6
7
8
9
10
11
studentLevel studentNum (int numCredits)
{
 	studentLevel title;
	
	if( numCredits < 32 ) title =  FRESHMAN ;
	else if ( numCredits < 64 ) title =  SOPHOMORE ;
	else if ( numCredits < 96 ) title =  JUNIOR ;
	else title =  SENIOR ;
	
	return title ;
}


Or simpler:
1
2
3
4
5
6
7
studentLevel studentNum (int numCredits)
{
	if( numCredits < 32 ) return FRESHMAN ;
	else if ( numCredits < 64 ) return SOPHOMORE ;
	else if ( numCredits < 96 ) return JUNIOR ;
	else return SENIOR ;
}
Thank you for your help.
Topic archived. No new replies allowed.