No Output, where is the problem?

DISCLAIMER: I don't want somebody to solve this for me, I just need someone to look the code over and let me know either where I went wrong (during file input, during output, etc.) or if I should scrap it and take a different approach.

I am supposed to read a file formatted as follows and store the information in corresponding struct members (arrays):
Firstname1 Lastname1 score1 score2 score3 score4
Firstname2 Lastname2 score1 . . .

example:
Sheila Duffy 119.43 89.92 60.85 80.68

I then need to find the highest score of each contestant as well as the highest overall score, then output the data as follows:
Firstname1 Lastname1 Highscore
Firstname2 Lastname2 Highscore

When I run my program, I don't get any output to the console. Could somebody point me in the right direction please?

Thank you in advance, and sorry for the mess of code.

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
#include <iostream>
#include <string>
#include <fstream>

int main() {

	//struct
	struct playerData {
		char fName[30] = { 0 };
		char lName[30] = { 0 };
		float longestDistance = 0;
	};

	//arrays
	playerData players[50];

	//variables
	std::ifstream inData;
	std::ofstream outData;
	float score1, score2, score3, score4;
	int playerCounter = 0;

	//read file
	inData.open("frisbee_throw.txt");
	//get first name, get last name, get scores, check for input failure
	for (int playerCounter = 0; playerCounter < 50; playerCounter++) {
		//first name loop
		for (int fNameCounter = 0; fNameCounter < 30; fNameCounter++) {
			inData >> players[playerCounter].fName[fNameCounter];
			//check for input failure
			if (players[playerCounter].fName[0] == ' ') {
				break;
			}
			//check for end of first name
			else if ((fNameCounter != 0) && (players[playerCounter].fName[fNameCounter] == ' ')) {
				//last name loop
				for (int lNameCounter = 0; lNameCounter < 30; lNameCounter++) {
					inData >> players[playerCounter].lName[lNameCounter];
					//check for end of last name
					if (players[playerCounter].lName[lNameCounter] == ' ') {
						//score read
						inData >> score1 >> score2 >> score3 >> score4;
						//check for highest score
					//score1
						if ((score1 > score2) && (score1 > score3) && (score1 > score4)) {
							players[playerCounter].longestDistance = score1;
							break;
						}
						//score2
						else if ((score2 > score1) && (score2 > score3) && (score2 > score4)) {
							players[playerCounter].longestDistance = score2;
							break;
						}
						//score3
						else if ((score3 > score1) && (score3 > score2) && (score3 > score4)) {
							players[playerCounter].longestDistance = score3;
							break;
						}
						//score4
						else if ((score4 > score1) && (score4 > score2) && (score4 > score3)) {
							players[playerCounter].longestDistance = score4;
							break;
						}
					}
					//next letter in last name
					else {
						continue;
					}
				}
			}
			//next letter in first name
			else
				continue;
		}
		//to break out of the main loop.
		if (players[playerCounter].fName[0] == ' ') {
			break;
		}
		else {
			continue;
		}
	}
	inData.close();

	//output of leaderboard
	for (int playerOutCount = 0; playerOutCount < playerCounter; playerOutCount++) {
		for (int fNameOutCount = 0; fNameOutCount < 30; fNameOutCount++) {
			std::cout << players[playerOutCount].fName[fNameOutCount];
			//check for input failure
			if (players[playerOutCount].fName[0] == ' ') {
				break;
			}
			//check for end of name
			else if ((fNameOutCount != 0) && (players[playerOutCount].fName[fNameOutCount] == ' ')) {
				//end of name, now last name loop
				std::cout << "  ";
				for (int lNameOutCount = 0; lNameOutCount < 30; lNameOutCount++) {
					std::cout << players[playerOutCount].lName[lNameOutCount];
					//check for end of last name
					if (players[playerOutCount].lName[lNameOutCount] == ' ') {
						//now score output
						std::cout << "  ";
						std::cout << players[playerOutCount].longestDistance << std::endl;
						break;
					}
					else
						continue;
				}
			}
			//next letter in first name
			else
				continue;
		}
		//break out of main out loop when input failure is detected
		if (players[playerOutCount].fName[0] == ' ') {
			break;
		}
		else
			continue;
	}
	return 0;
} 
Last edited on
Some points.

1. Writing 120 lines all in a single function isn't good style.
Your two major phases of 'input' and 'output' should be separated.

2. Writing 120 lines of code without testing anything along the way is poor practice.
If you had a more modular approach to functions, you could test as you go.

The first thing would be to use the debugger, put a breakpoint on line 86 and then examine your playerCounter and players array to see if they contain anything resembling what you expect.
Topic archived. No new replies allowed.