THANKS!!

!!!
Last edited on
Hello Zachy186,

The first problem I found is the line const int SIZE = 9;. First you defined this after you tried to use it four time to define arrays. This does not work. This line needs to be the first line of "main" to work properly.

Then I discovered that it really needs to be above "main" so the whole file can see it because i found that one or more of the functions that follow main will use it.

In case 4 you have "int" in the second parameter. It should not be there. Only in the prototype and the function definition.

At the end of "main" "return 0;" is not required, but it is good form and some times useful as a break point in the IDE to stop the program to heck what variables hold.

After "main" it looks all the functions have problems that need addressed. I say at least one missing comma and one variable of the wrong type.

The first function "playernames" is a void function, but you are trying to return zero at the end of the function. This does not work.

I compiled the program and it said I have 52 errors to deal with. This will take awhile to sort out.

You should really compile your program before you post it. This way if there are any errors that you do not understand you can include them in your post.

Compile your program and see what errors you can fix.

Hope that helps,

Andy
I just cannot get the variables to pass through the arguments to the other function

You must be kidding: the compiler complains about a number of errors and warnings and refuses to compile.

At first sight:
- Why do you declare all your variables at the beginning of functions? Do declare them where you really need them.
- You need to add all prototypes before ‘main()’, not just a couple of them.
- What is your code between lines 103-127 expected to do? Should it sort the arrays?
- What’s there in file “pch.h”?
- Please remember a C-style array ‘decays’ into a pointer to its first element when it’s passed as argument to a function - you usually want to add a parameter which informs about the size of the array.

Please, try to describe better your problem.

Hello Zachy186,

Enoizat makes some good points:

Why do you declare all your variables at the beginning of functions? Do declare them where you really need them.

I still do not understand why burring the variables in the program is a good idea just do what feels right to you and what you are comfortable with.

When I finished the prototypes several errors went away.

AS to the "pch.h" file we both know that VS generates this file, but it is best to leave this line out when posting code here. Most people can not use this file and it cuts out unnecessary comments.

When I started testing the program the first problem I had was checking that the file was opened. For me the return closed the console window before I could read the message.
This is my fix:
1
2
3
4
5
6
7
8
	if (!inFile)
	{
		// Display an error message.
		cout << "Error opening the file.\n";
		std::this_thread::sleep_for(std::chrono::seconds(4));  // Requires header files "chrono" and "thread"

		return 1;  // <--- the 1 means there is a problem.
	}


Then I had a problem reading the file. First I forgot to create the file so I did not see the message before the console window closed when the "return 0" was reached. BTW it should be "return 1" with the 1 meaning there was a problem and zero meaning there was no problem when the program ended.

Like "std::cin >>" "inFile >>" works the same way. First it will read up to the first white space or new line whichever comes first leaving anything that may be left in the input buffer. This worked up to where the next read was "first base". Only first was put into the variable and "base" was left in the input buffer. When "inFile >> score[count]" expected a number to be read all it got was a string causing the input file stream to fail and nothing else was read. For string variables it is best to use "std::getline(inFile, stringVariable);". This way if there is more than one word it will get every thing on the line.

You can mix "std::getline()" and "std::cin" or "inFile", but after the "std::cin" or "inFile" you need to clear the input buffer before the next "std::getline()". The following code fixed the read problem:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
for (int count = 0; count < SIZE; count++)
{
	std::getline(inFile, names[count]);
	inFile >> number[count];
	inFile.ignore(std::numeric_limits<std::streamsize>::max(), '\n');  // <--- Requires header file <limits>.

	std::getline(inFile, position[count]);

	inFile >> score[count];
	inFile.ignore(std::numeric_limits<std::streamsize>::max(), '\n');  // <--- Requires header file <limits>.

	std::cout << std::endl;

} //for loop applying .txt to arryfiles  <--- Not the best description for reading a file. 

Once it was reading the file and storing the information properly I tested case one and it worked as it should.

Now I have to test the rest.

Hope that helps,

Andy

P.S. forgot to mention when using a constant put it as your first variable definition before it is used. And if it is a global variable put soon after the includes.
Last edited on
Thank you all for your help
Please do not remove your question. It should be left to help others with similar problems to see what to do.
Aw man why did you remove your post?
Topic archived. No new replies allowed.