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
#include <iostream>
#include <string>
#include <fstream>
#pragma warning(disable:4996)
usingnamespace 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;
}
elseif (Blue[5] < White[6])
{
cout << "White wins Ippon." << endl;
}
elseif (Blue[7] > White[8] && Blue[7] >= '2')
{
cout << "Blue wins by Ippon." << endl;
}
elseif (Blue[7] < White[8] && White[8] >= '2')
{
cout << "White wins by Ippon." << endl;
}
elseif (Blue[7] > White[8])
{
cout << "Blue wins by Waza-ari." << endl;
}
elseif (Blue[7] < White[8])
{
cout << "White wins by Waza-ari." << endl;
}
elseif (Blue[9] > White[10])
{
cout << "Blue wins by Yuko." << endl;
}
elseif (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
}
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;
...