Need help with program debug please

I'm supposed to be debugging this source file so that it works properly. There are a total of 6 errors in the file and I've found 4 so far. I can't figure out the last two errors. I have an idea of where the next one is but i can't figure it out. I'll include both source files. The original and the one i've debugged so far. Any help would be appreciated in helping me understand this.

This is the original debug file:
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
// Debug Program -- there are 6 errors in this program
// Correct this program

#include <iostream>
#include <iomanip>


using namespace std;
 
void readData(ifstream& inputFile, int list[], int size);
void holdscrn( );    // void function to hold screen open before exit


int main()
{
    int scores[8] = {0};

    ifstream infile;

    infile.open("TestScoresData.txt");

	if (infile)
	{
		cout << "Cannot open the input file. Program terminates!" 
			 << endl;
		holdscrn( );   // Hold screen before exit	 
		return 1;
	}

	readData(infile, scores, 8);
	print(scores, 8);
	cout << endl;

	infile.close();
	holdscrn( );   // Hold screen before exit
	return 0;
}

void readData(ifstream& inputFile, int list[], int size)
{
	int score;
	int index;

	cin >> score;

	while (inputFile)
	{
		index = score / 25;

		if (index == size)
			index--;
		if (index < size)
			list[index]++;

		inputFile >> score;
	}
    return 0;
}

void print(int list[], int size)
{
    int range;
    int lowRange = 0;
    int upperRange = 24;

    cout << "   Range       # of Students" << endl;

    for (range = 0; range < size; range++)
    {
        cout << setw(3) << lowRange << " - " 
             << upperRange << setw(15)
             << list[range] << endl;
        lowRange = upperRange + 1;
        upperRange = upperRange + 25;
        if (range == size - 2)
            upperRange++;
    }
    cout << endl;
    return;
}

void holdscrn( )   // void function to hold screen open before exit
{
    char holdscreen;
    cout << "\n\n\tEnter one character and press return to exit program:  ";
    cin >> holdscreen;

    return;
}


and this is what i've gotten so far:
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
// Debug Program -- there are 6 errors in this program
// Correct this program

#include <iostream>
#include <iomanip>
#include <fstream>	 // error 1 no file stream header was included


using namespace std;
 
void readData(ifstream& inputFile, int list[], int size);
void holdscrn( );    
void print(int list[], int size); // error 2 void function wasn't delcared

int main()
{
    int scores[8] = {0};

    ifstream infile;

    infile.open("TestScoresData.txt");

	if (!infile)	// error 3 made it equal to not infile
	{
		cout << "Cannot open the input file. Program terminates!" 
			 << endl;
		holdscrn( );   	 
		return 1;
	}

	readData(infile, scores, 8);
	print(scores, 8);
	cout << endl;

	infile.close();
	holdscrn( );   
	return 0;
}

void readData(ifstream& inputFile, int list[], int size)
{
	int score;
	int index;

	cin >> score;   //I think the next error has something to do with this
                               //It's not reading the inputFile but waiting for a input 
                               //response from the user which throws off the end total

	while (inputFile)
	{
		index = score / 25;

		if (index == size)
			index--;
		if (index < size)
			list[index]++;

		inputFile >> score;
	}
    return;   // error 4 was returning a value
}

void print(int list[], int size)
{
    int range;
    int lowRange = 0;
    int upperRange = 24;

    cout << "   Range       # of Students" << endl;

    for (range = 0; range < size; range++)
    {
        cout << setw(3) << lowRange << " - " 
             << upperRange << setw(15)
             << list[range] << endl;
        lowRange = upperRange + 1;
        upperRange = upperRange + 25;
        if (range == size - 2)
            upperRange++;
    }
    cout << endl;
    return;
}

void holdscrn( )   
{
    char holdscreen;
    cout << "\n\n\tEnter one character and press return to exit program:  ";
    cin >> holdscreen;

    return;
}


Edit: Last minute edit that I thought might be needed maybe? This is the information that is in the resource file that infile is pulling from.

76 89 150 135 200 76 12 100 150 28 178 189 167 200 175 150 87 99 129
149 176 200 87 35 157 189
Last edited on
It might help if you described what the program should be doing.
I wasn't given an explanation for what the program is supposed to do. I was just supposed to debug it. From what I have gathered of the program though it is supposed to take the resource file with those numbers at the bottom of my first post and then spit out a table with a varying ranges and the "# of students" who fall within those ranges according to the numbers read in from the resource file.

Edit: So range 1-24 would be 1 student, 25-50 would be 1 student, 51-75 would be 0 students and so on.
Last edited on
I found another error but can't seem to find the 6th one. The program works fine with 5 errors fixed so I'm assuming there is a logic error somewhere but I can't figure it out because from what I can tell the program is running as intended.

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
// Debug Program -- there are 6 errors in this program
// Correct this program

#include <iostream>
#include <iomanip>
#include <fstream>	 // error 1 no file stream header was included


using namespace std;
 
void readData(ifstream& inputFile, int list[], int size);
void holdscrn( );    
void print(int list[], int size); // error 2 void function wasn't delcared

int main()
{
    int scores[8] = {0};

    ifstream infile;

    infile.open("TestScoresData.txt");

	if (!infile)	// error 3 made it equal to not infile
	{
		cout << "Cannot open the input file. Program terminates!" 
			 << endl;
		holdscrn( );   	 
		return 1;
	}

	readData(infile, scores, 8);
	print(scores, 8);
	cout << endl;

	infile.close();
	holdscrn( );   
	return 0;
}

void readData(ifstream& inputFile, int list[], int size)
{
	int score;
	int index;

	inputFile>> score;   // error 5 changed cin to inputFile

	while (inputFile)
	{
		index = score / 25;

		if (index == size)
			index--;
		if (index < size)
			list[index]++;

		inputFile >> score;
	}
    return;   // error 4 was returning a value
}

void print(int list[], int size)
{
    int range;
    int lowRange = 0;
    int upperRange = 24;

    cout << "   Range       # of Students" << endl;

    for (range = 0; range < size; range++)
    {
        cout << setw(3) << lowRange << " - " 
             << upperRange << setw(15)
             << list[range] << endl;
        lowRange = upperRange + 1;
        upperRange = upperRange + 25;
        if (range == size - 2)
            upperRange++;
    }
    cout << endl;
    return;
}

void holdscrn( )   
{
    char holdscreen;
    cout << "\n\n\tEnter one character and press return to exit program:  ";
    cin >> holdscreen;

    return;
}


Edit: Just wanted to update this just in case anyone was trying to help me so I could let them know I figured it out aside from the allusive 6th error.
Last edited on
Topic archived. No new replies allowed.