Nothing is printing to the screen

I assume I have a logical error but I can't pick up on it. Nothing is printing to the screen except: "File opened successfully."

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
#include<iostream>
#include<fstream>
using namespace std;

int main()
{
	int frame = 0;
	int bin = 0;
	int frame1=0, bin1=0;
	int counter = 0, amplitude[25][1024];
	int max=0, highestMax=0, highestFrame=0, highestBin=0;

	ifstream audioFile;
	audioFile.open("audioframes.txt");
	int data;
	audioFile >> data;
	ofstream outFile;

	if (!audioFile.is_open()) {
		cout << "Failure to open file." << endl;
	}
	else {
		cout << "File opened successfully." << endl;
		if (counter % 3 == 2)
		{
			amplitude[frame][bin] = data;
			bin++;
		}
		if ((frame != 24) && (bin == 1024))
{
		bin = 0;
		frame++;
}
counter++;
		}
	audioFile.close();

	int i = 1, j = 0;
	while (i < 25) 
	{
		if ((i == 0) && (j == 0))
		{
			cout << "The maximum amplitude per frame is:" << endl;
			cout << "Frame:" << "\nBin:" << "\nMaximum Amplitude:" << endl;
			outFile << "The maximum amplitude per frame is:" << endl;
			outFile << "Frame:" << "\nBin:" << "\nMaximum Amplitude:" << endl;
		}
		i++;
	}
	while (j < 1024)
	{
    if(j==0)
	{
		max = amplitude[i][j];
	}
	if (amplitude[i][j] > max)
	{
		max = amplitude[i][j];
		frame1 = i;
		bin1 = j;
	}
	if(amplitude[i][j]>highestMax)
	{
		highestMax = amplitude[i][j];
		highestFrame = i;
		highestBin = j;
	}
	}
	cout << frame1 << "\t" << bin1 << "\t" <<max << endl;

	return 0;
}

The condition at line 41 is never true. Since i is set to 1 at line 38 and incremented at line 48, it's never zero.

Then the loop at line 50 is infinite because j is never changed. As a result, the program prints "File opened successfully" and then just sits there doing nothing.

As an aside, what's going on at lines 24-32? Counter and frame are always zero so these lines have no effect.
Thanks for your help I fixed what you said but I'm still getting problems. Lines the outputs at lines 43 & 44 are blank when printed to the screen. Also the max at line 69 displays a wrong value (it seems like a combination of the amplitudes).
Probably more errors with the logic. Here's what I got 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
#include<iostream>
#include<fstream>
using namespace std;

int main()
{
	int frame = 1;
	int bin = 0;
	int frame1 = 0, bin1 = 0;
	int counter = 0, amplitude[25][1024];
	int max = 0, highestMax = 0, highestFrame = 0, highestBin = 0;

	ifstream audioFile;
	audioFile.open("audioframes.txt");
	int data;
	audioFile >> data;
	ofstream outFile;

	if (!audioFile.is_open()) {
		cout << "Failure to open file." << endl;
	}
	else {
		cout << "File opened successfully." << endl;
		if (counter % 3 == 2)
		{
			amplitude[frame][bin] = data;
			bin++;
		}
		if ((frame != 24) && (bin == 1024))
		{
			bin = 0;
			frame++;
		}
		counter++;
	}
	audioFile.close();

	int i = 0, j = 0;
	while (i < 25)
	{
		if ((i == 0) && (j == 0))
		{
			cout << "The maximum amplitude per frame is:" << endl;
			cout << "Frame:" << "\nBin:" << "\nMaximum Amplitude:" << endl;
			outFile << "The maximum amplitude per frame is:" << endl;
			outFile << "Frame:" << "\nBin:" << "\nMaximum Amplitude:" << endl;
		}
		i++;
	}
	while (j < 1024)
	{
		if (j == 0)
		{
			max = amplitude[i][j];
		}
		if (amplitude[i][j] > max)
		{
			max = amplitude[i][j];
			frame1 = i;
			bin1 = j;
		}
		if (amplitude[i][j]>highestMax)
		{
			highestMax = amplitude[i][j];
			highestFrame = i;
			highestBin = j;
		}
		j++;
	}
	cout << frame1 << "\t" << bin1 << "\t" << max << endl;

	return 0;
}
You only ever read a single number from audioFile (at line 16). Does the file contain more than one number?

Should lines 24-34 be in a loop? Right now they are not.

Because lines 24-34 are not in a loop, counter is 0 the one time that line 24 executes, so the expression is false and amplitude is never updated. As a result amplitude is completely uninitialized.

You never open outFile, so lines 45&46 will never output anything.

I suggest you work on the code that reads the input. Add some temporary code to print out what you read. Make sure that's working correctly before moving on to the processing after line 25.
Topic archived. No new replies allowed.