file looping issue, trying to loop once too many pulling from a file

I am very new please go easy on me as I know I have things to work out. I have a file names judoscores.txt that I have to use a c++ program to take the scores and let know who won the match Blue or White. I have the program working although I used no functions I still need to try and separate it but I have trouble with that part. This is 1 of the first programs I have made that wasn't super basic. 1 problem is I get an error so I had to add the #pragma warning(disable:4996) or it wont finish. Then my ending loop is trying to once 1 more so it is giving errors at end of program. The program actually works I just want to fix the pragma error, get it to loop 1 less so it doesn't screw up at end and break up the program into functions. Any help would be tons appreciated. Thank you. I will also try to make the comments better.


Here is the c++ program...





Here is the file text for judoscores.txt

13
Blue 0 2 0
White 0 1 2
Blue 0 0 2
White 0 1 0
Blue 0 1 1
White 0 0 0
Blue 0 0 2
White 0 1 1
Blue 0 1 0
White 0 1 1
Blue 0 0 1
White 0 0 0
Blue 0 0 2
White 0 0 0
Blue 0 0 0
White 1 0 0
Blue 1 0 0
White 0 1 1
Blue 0 0 1
White 0 1 1
Blue 0 1 0
White 0 0 1
Blue 0 0 1
White 1 0 1
Blue 1 0 0
White 0 1 0

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
 #include <iostream>
 #include <string>
 #include <fstream>
 #pragma warning(disable:4996)
 using namespace std;

 int main()
 {

 short loop = 0; //short for loop for input
 string Blue; //this will contain the data read from the file
 string White; //this will contain the data read from the file
 ifstream myfile("judoscores.txt"); //opening the file.
 int lengthOfString;

 if (myfile.is_open()) //if the file is open
 {
 getline(myfile, Blue); // ignore first line
 while (!myfile.eof()) //while the end of file is NOT reached
 {
 getline(myfile, Blue); //get one line from the file
 cout << Blue << endl;
 getline(myfile, White); //get one line from the file
 cout << White << endl;
 cout << "============" << endl;

 char charactersB[9];
 char charactersW[10];

 lengthOfString = Blue.length();
 Blue.copy(charactersB, lengthOfString);

 lengthOfString = White.length();
 White.copy(charactersW, lengthOfString);

 if (Blue[5] > White[6])
 {
 cout << "Blue wins by Ippon." << endl;
 }
 else
 if (Blue[5] < White[6])
 {
 cout << "White wins Ippon." << endl;
 }
 else
 if (Blue[7] > White[8] && Blue[7] >= '2')
 {
 cout << "Blue wins by Ippon." << endl;
 }
 else
 if (Blue[7] < White[8] && White[8] >= '2')
 {
 cout << "White wins by Ippon." << endl;
 }
 else
 if (Blue[7] > White[8])
 {
 cout << "Blue wins by Waza-ari." << endl;
 }
 else
 if (Blue[7] < White[8])
 {
 cout << "White wins by Waza-ari." << endl;
 }
 else
 if (Blue[9] > White[10])
 {
 cout << "Blue wins by Yuko." << endl;
 }
 else
 if (Blue[9] < White[10])
 {
 cout << "White wins by Yuko." << endl;
 }
 cout << endl;



 loop++;

 }
 myfile.close(); //closing the file
 }
 else cout << "Unable to open file"; //if the file is not open output

 }
For the 'once too many' change the while loop:
1
2
3
4
5
6
7
 while (!myfile.eof() getline(myfile, Blue) && getline(myfile, White)) //while the end of file is NOT reached
 {
 getline(myfile, Blue); //get one line from the file
 cout << Blue << endl;
 getline(myfile, White); //get one line from the file
 cout << White << endl;
...


What is the problem with the warning 4996?
I did get it working I just now need to divide it up into functions so it doesn't look so bad. Thank you.

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

int main()
{
	string Blue; //this will contain the data read from the file
	string White; //this will contain the data read from the file
	string matches; // number of matches
	string filename;
	fstream myfile;

	cout << "Enter the file name: ";
	cin >> filename;
	myfile.open(filename); //opening the file.
	if (filename != "judoscores.txt")
	{
		cout << "Error: please enter the correct file." << endl;
		return 0;
	}
	cout << endl;
	getline(myfile, matches);
	int matchesF = std::stoi(matches); //string to integer

	if (myfile.is_open()) //if the file is open
	{
		for (int x = 0; x < matchesF; x++) //while the end of file is NOT reached
		{
			getline(myfile, Blue); //get one line from the file
			cout << Blue << endl;
			getline(myfile, White); //get one line from the file
			cout << White << endl;
			cout << "============" << endl;


			const char * BlueC = Blue.c_str();
			const char * WhiteC = White.c_str();

			if (Blue[5] > White[6])
			{
				cout << "Blue wins by Ippon.\n" << endl;
			}
			else
				if (Blue[5] < White[6])
				{
					cout << "White wins Ippon.\n" << endl;
				}
				else
					if (Blue[7] > White[8] && Blue[7] >= '2')
					{
						cout << "Blue wins by Ippon.\n" << endl;
					}
					else
						if (Blue[7] < White[8] && White[8] >= '2')
						{
							cout << "White wins by Ippon.\n" << endl;
						}
						else
							if (Blue[7] > White[8])
							{
								cout << "Blue wins by Waza-ari.\n" << endl;
							}
							else
								if (Blue[7] < White[8])
								{
									cout << "White wins by Waza-ari.\n" << endl;
								}
								else
									if (Blue[9] > White[10])
									{
										cout << "Blue wins by Yuko.\n" << endl;
									}
									else
										if (Blue[9] < White[10])
										{
											cout << "White wins by Yuko.\n" << endl;
										}
		}
		myfile.close(); //closing the file
	}

}
Topic archived. No new replies allowed.