<file_sep>#include <stdio.h>
#include <stdlib.h>

//global variable for molar mass, utilized a lot, better off global than passed as parameter
float M = 0;
float calcMM (char* substance, int length, int start);
int subscript (char* substance, int position);

int main (int argc,char* argv[]) {
	if(argc == 1) { //no command line argument for compound
		char compound1[50]; //reasonable to assume no compound over 25 letters will be used
		printf ("Please enter a compound who's molar mass you would like to calculate: ");
		int i = 0;
		compound1[i] = getchar(); //analyze input char by char
		while (compound1[i] != '\0' && compound1[i] != '\n' && i < 25) { //store into char array until input ends
			if (!(compound1[i] == 40 || compound1[i] == 41 || (compound1[i] > 47 && compound1[i] < 58) || 
			(compound1[i] > 64 && compound1[i] < 91) || (compound1[i] > 96 && compound1[i] < 123))) {
				printf ("Incorrect characters used to represent a compound"); //checked for invalid characters
				return -1;
			}
			i++; //i = number of characters, last compound[i] stores '\n'
			compound1[i] = getchar(); //update for next loop
		}
		
		float theMM = calcMM(compound1, i, 0); //calculate the molar mass
		if (theMM < 0) //error check
			printf ("An error has occurred, please check the characters used for the formulae");
		else 
			printf ("\nThe molar mass is: %.3f", theMM);
	} else if (argc > 1) { //with command line argument
		for (int loops = 1; loops < argc; loops++) { //run for cmd line arguments - 1
			int j = 0;
			while (argv[loops][j] != '\0' && argv[loops][j] != '\n' && j < 25) { //store variables until input ends
				if (!(argv[loops][j] == 40 || argv[loops][j] == 41 || (argv[loops][j] > 47 && argv[loops][j] < 58) || 
				(argv[loops][j] > 64 && argv[loops][j] < 91) || (argv[loops][j] > 96 && argv[loops][j] < 123))) {
					printf ("Incorrect characters used to represent a compound"); //checked for invalid characters
					return -1;
				}
				j++; //j = number of characters, last compound[j] stores '\n'
			}
			
			float theMM = calcMM(argv[loops], j, 0); //calc molar mass
			if (theMM < 0) //error check
				printf ("An error has occurred, please check the characters used for the formulae");
			else 
				printf ("\nThe molar mass is: %.3f", theMM);
			M = 0; //reset molar mass to 0 for next compound to be calculated
		}
	}
	
	return 0;
}

int subscript (char* substance, int position) { //new function used to find numeric subscripts
	int number1 = substance[position];
	if (number1 < 48 || number1 > 57) //double check that subscript after compound name is a valid number
		return -1;
	number1 -= 48;
	if (substance[position+1] > 47 && substance[position+1] < 58) { //calc the subscript on compound
		int number2 = substance[position+1];
		number2 -= 48;
		number1 *= 10;
		number1 += number2;
	}
	
	return number1;
}

float calcMM (char* substance, int length, int start) {
	
	int i = start; int multiple;
	float bracketMM = 0; float tempMM = 0;
	for (i; i < start+length; i++) {
		switch (substance[i]) { //The switch cased used to determined molarmass by finding elements and subscripts
			case '1':
			case '2':
			case '3':
			case '4':
			case '5':   //cases for any subscript between 1 - 99 
			case '6':
			case '7':
			case '8':
			case '9':
				tempMM = M; //record molar mass
				if (substance[i-1] > 96 && substance[i-1] < 123) {
					calcMM (substance, 2, i-2); //repeat calc for past 2 char if lowercase letter before subscript
				} else {
					calcMM (substance, 1, i-1); //repeat calc for past char if uppercase letter before subscript
				}
				tempMM = M - tempMM; //find molar mass of element/compound that the subscript applies to
			
				multiple = subscript (substance, i); //find subscript (number) after element name
				if (multiple < 1)
					return -1;
				M = M + (multiple-2)*tempMM; //apply the necessary additions to the molar mass according to subscript
				//2 less than subscript because function has gone through masses twice already
				break;
			case '(':
				bracketMM = M; //temp variable, molar mass of compound before brackets
				break;
			case ')':
				bracketMM = M - bracketMM; //find molar mass of compound inside brackets
				if (substance[i+1] > 48 && substance[i+1] < 58) {
					i++;
					multiple = subscript(substance, i); //find the subscript after brackets
					if (multiple < 1)
						return -1;
					M = M + (multiple-1)*bracketMM; //1 less since function went through masses already
					break;
				} else
					return -1;
				break;
				
			//Switch cases below are for all the compounds in the periodic table (for the first 118 elements)
			case 'A': 
				if (substance[i+1] > 96 && substance[i+1] < 123) {
					i++;
					switch (substance[i]) {
						case 'c':
							M += 227; //actinium atom
							break;
						case 'g':
							M += 107.868; //silver atom
							break;
						case 'l':
							M += 26.9815; //aluminium atom
							break;
						case 'm':
							M += 243; //americium atom
							break;
						case 'r':
							M += 39.984; //argon atom
							break;
						case 's':
							M += 74.922; //arsenic atom
							break;
						case 't':
							M += 209; //astatine atom
							break;
						case 'u':
							M += 196.967; //gold atom
							break;
						default:
							return -1;
							break;
					}
				} else {
					return -1; //if only 'A' was entered, invalid element
				}
				break;
			case 'B': 
				if (substance[i+1] > 96 && substance[i+1] < 123) {
					i++;
					switch (substance[i]) {
						case 'a':
							M += 137.327; //barium atom
							break;
						case 'e':
							M += 9.0122; //beryllium atom
							break;
						case 'h':
							M += 272; //bohrium atom
							break;
						case 'i':
							M += 208.98; //bismuth atom
							break;
						case 'k':
							M += 247; //berkelium atom
							break;
						case 'r':
							M += 79.904; //bromine atom
							break;
						default:
							return -1;
							break;
					}
				} else {
					M += 10.811; //boron atom
				}
				break;
			case 'C':
				if (substance[i+1] > 96 && substance[i+1] < 123) {
					i++;
					switch (substance[i]) {
						case 'a':
							M += 40.078; //calcium atom
							break;
						case 'd':
							M += 112.411; //cadmium atom
							break;
						case 'e':
							M += 140.116; //cerium atom
							break;
						case 'f':
							M += 251; //californium atom
							break;
						case 'l':
							M += 35.453; //chlorine atom
							break;
						case 'g':
							M += 247; //curium atom
							break;
						case 'n':
							M += 285; //copernicium atom
							break;
						case 'o':
							M += 58.933; //cobalt atom
							break;
						case 'r':
							M += 51.996; //chromium atom
							break;
						case 's':
							M += 132.905; //cesium atom
							break;
						case 'u':
							M += 63.546; //copper atom
							break;
						default:
							return -1;
							break;
					}
				} else {
					M += 12.0101; //carbon atom
				}
				break;
			case 'D': 
				if (substance[i+1] > 96 && substance[i+1] < 123) {
					i++;
					switch (substance[i]) {
						case 'b':
							M += 268; //dubnium atom
							break;
						case 's':
							M += 281; //darmstadtium atom
							break;
						case 'y':
							M += 162.50; // dysprosium atom
							break;
						default:
							return -1;
							break;
					}
				} else {
					return -1; //error check if only 'D' was entered, invalid element
				}
				break;
			case 'E': 
				if (substance[i+1] > 96 && substance[i+1] < 123) {
					i++;
					switch (substance[i]) {
						case 'u':
							M += 151.964; // europium atom
							break;
						case 'r':
							M += 167.259; // erbium atom
							break;
						case 's':
							M += 251; //einsteinium atom
							break;
						default:
							return -1;
							break;
					}
				} else {
					return -1; //if only 'E' was entered, invalid element
				}
				break;
			case 'F': 
				if (substance[i+1] > 96 && substance[i+1] < 123) {
					i++;
					switch (substance[i]) {
						case 'e':
							M += 55.845; //iron atom
							break;
						case 'l':
							M += 289; //flerovium atom
							break;
						case 'm':
							M += 257; //fermium atom
							break;
						case 'r':
							M += 223; //francium atom
							break;
						default:
							return -1;
							break;
					}
				} else {
					M += 18.998; // fluorine atom
				}
				break;
			case 'G': 
				if (substance[i+1] > 96 && substance[i+1] < 123) {
					i++;
					switch (substance[i]) {
						case 'a':
							M += 69.723; // gallium atom
							break;
						case 'd':
							M += 157.25; // gadolinium atom
							break;
						case 'e':
							M += 72.64; // germanium atom
							break;
						default:
							return -1;
							break;
					}
				} else {
					return -1; //if only 'G' was entered, invalid element
				}
				break;
			case 'H':
				if (substance[i+1] > 96 && substance[i+1] < 123) {
					i++;
					switch (substance[i]) {
						case 'e':
							M += 4.0026; //helium atom
							break;
						case 'f':
							M += 178.49; //hafnium atom
							break;
						case 'g':
							M += 200.59; // mercury atom
							break;
						case 'o':
							M += 164.93; //holmium atom
							break;	
						case 's':
							M += 270; //hassium atom
							break;
						default:
							return -1;
							break;
					}
				} else {
					M += 1.0079; // hydrogen atom
				}
				break;
			break;
			case 'I': 
				if (substance[i+1] > 96 && substance[i+1] < 123) {
					i++;
					switch (substance[i]) {
						case 'n':
							M += 114.818; //indium atom
							break;
						case 'r':
							M += 192.217; //iridum atom
							break;
						default:
							return -1;
							break;
					}
				} else {
					M += 126.905; //iodine atom
				}
			case 'J': 
				return -1; //no element with a letter 'J' to start its name
				break;
			case 'K':
				if (substance[i+1] > 96 && substance[i+1] < 123) {
					i++;
					switch (substance[i]) {
						case 'r':
							M += 83.978; //krypton atom
							break;
						default:
							return -1;
							break;
					}
				} else {
					M += 39.098; //potassium atom
				}
				break;
			case 'L': 
				if (substance[i+1] > 96 && substance[i+1] < 123) {
					i++;
					switch (substance[i]) {
						case 'a':
							M += 138.906; //lanthanum atom
							break;
						case 'i':
							M += 6.941; //lithium atom
							break;
						case 'r':
							M += 262; //lawrencium atom
							break;
						case 'u':
							M += 174.967; //lutetium atom
							break;
						case 'v':
							M += 293; //livermorium atom
							break;
						default:
							return -1;
							break;
					}
				} else {
					return -1; //error check for if 'L' was entered, invalid element
				}
				break;
			case 'M':
				if (substance[i+1] > 96 && substance[i+1] < 123) {
					i++;
					switch (substance[i]) {
						case 'c':
							M += 288; //moscovium atom
							break;
						case 'd':
							M += 258; //mendelevium atom
							break;
						case 'g':
							M += 24.305; //magnesium atom
							break;
						case 'n':
							M += 54.938; //manganese atom
							break;
						case 'o':
							M += 95.94; //molybdenum atom
							break;
						case 't':
							M += 276; //meitnerium atom
							break;
						default:
							return -1;
							break;
					}
				} else {
					return -1; //if only 'M' was entered, invalid element
				}
				break;
			case 'N': 
				if (substance[i+1] > 96 && substance[i+1] < 123) {
					i++;
					switch (substance[i]) {
						case 'a':
							M += 22.999; //sodium atom
							break;
						case 'b':
							M += 92.906; //niobium atom
							break;
						case 'd':
							M += 144.24; //neodymium atom
							break;
						case 'e':
							M += 20.18; //neon atom
							break;
						case 'h':
							M += 284; //nihonium atom
							break;
						case 'i':
							M += 58.693; // nickel atom
							break;
						case 'o':
							M += 259; //nobelium atom
							break;
						case 'p':
							M += 237; //neptunium atom
							break;
						default:
							return -1;
							break;
					}
				} else {
					M += 14.007; // nitrogen atom
				}
				break;
			case 'O':
				if (substance[i+1] > 96 && substance[i+1] < 123) {
					i++;
					switch (substance[i]) {
						case 'g':
							M += 294; //oganesson atom
							break;
						case 's':
							M += 190.23; // osmium atom
							break;
						default:
							return -1;
							break;
					}
				} else {
					M += 16; // oxygen atom
				}
				break;
			case 'P': 
				if (substance[i+1] > 96 && substance[i+1] < 123) {
					i++;
					switch (substance[i]) {
						case 'a':
							M += 231.036; //protactinium atom
							break;
						case 'b':
							M += 207.2; //lead atom
							break;
						case 'd':
							M += 106.42; // palladium atom
							break;
						case 'm':
							M += 145; // promethium atom
							break;
						case 'o':
							M += 209; //polonium atom
							break;
						case 'r':
							M += 140.908; // praseodymium atom
							break;
						case 't':
							M += 195.078; //platinum atom
							break;
						case 'u':
							M += 244; //plutonium atom
							break;
						default:
							return -1;
							break;
					}
				} else {
					M += 30.9738; // phosphorus atom
				}
				break;
			case 'Q': 
				return -1; //no element with name starting with 'Q'
				break;
			case 'R': 
				if (substance[i+1] > 96 && substance[i+1] < 123) {
					i++;
					switch (substance[i]) {
						case 'a':
							M += 226; //radium atom
							break;
						case 'b':
							M += 85.468; //rubidium atom
							break;
						case 'e':
							M += 186.207; //rhenium atom
							break;
						case 'f':
							M += 267; //rutherfordium atom
							break;	
						case 'g':
							M += 280; //roentgenium atom
							break;
						case 'h':
							M += 102.96; //rhodium atom
							break;
						case 'n':
							M += 222; //radon atom
							break;
						case 'u':
							M += 101.07; //ruthenium atom
							break;
						default:
							return -1;
							break;
					}
				} else {
					return -1; //error check if only 'R' was entered, invalid element
				}
				break;
			case 'S': 
				if (substance[i+1] > 96 && substance[i+1] < 123) {
					i++;
					switch (substance[i]) {
						case 'b':
							M += 121.76; // antimony atom
							break;
						case 'c':
							M += 44.956; // scandium atom
							break;
						case 'e':
							M += 78.96; // selenium atom
							break;
						case 'g':
							M += 271; //seaborgium atom
							break;
						case 'i':
							M += 28.086; // silicon atom
							break;
						case 'm':
							M += 150.36; // samarium atom
							break;
						case 'n':
							M += 118.71; // tin atom
							break;
						case 'r':
							M += 87.62; // strontium atom
							break;
						default:
							return -1;
							break;
					}
				} else {
					M += 32.065; // sulfur atom
				}
				break;
			case 'T':
				if (substance[i+1] > 96 && substance[i+1] < 123) {
					i++;
					switch (substance[i]) {
						case 'a':
							M += 180.948; // tantalum atom
							break;
						case 'b':
							M += 158.925; // terbium atom
							break;
						case 'c':
							M += 98; // technetium atom
							break;
						case 'e':
							M += 127.6; // tellurium atom
							break;
						case 'h':
							M += 232.038; //thorium atom
							break;
						case 'i':
							M += 47.867; // titanium atom
							break;
						case 'l':
							M += 204.383; //thallium atom
							break;
						case 'm':
							M += 168.934; // thulium atom
							break;
						case 's':
							M += 294; //tennessine atom
							break;
						default:
							return -1;
							break;
					}
				} else {
					return -1; //error check if only 'T' was entered, invalid element
				}
				break;
			case 'U': M += 238.029; //uranium atom
			break;
			case 'V': M += 50.942; // vanadium atom
			break;
			case 'W': M += 183.84; //tungsten atom
			break;
			case 'X': 
				if (substance[i+1] > 96 && substance[i+1] < 123) {
					i++;
					switch (substance[i]) {
						case 'a':
							M += 131.293; // xenon atom
							break;
						default:
							return -1;
							break;
					}
				} else {
					return -1; //if only 'X' was entered, invalid element
				}
				break;
			case 'Y': 
				if (substance[i+1] > 96 && substance[i+1] < 123) {
					i++;
					switch (substance[i]) {
						case 'b':
							M += 173.04; // ytterbium atom
							break;
						default:
							return -1;
							break;
					}
				} else {
					M += 88.906; // yttrium atom
				}
			break;
			case 'Z':
				if (substance[i+1] > 96 && substance[i+1] < 123) {
					i++;
					switch (substance[i]) {
						case 'n':
							M += 65.409; // zinc atom
							break;
						case 'r':
							M += 91.225; // zirconium atom
							break;
						default:
							return -1;
							break;
					}
				} else {
					return -1; //error check if only 'Z' was entered, invalid element
				}
				break;
			default: 
				return -1;
				break;
		}
	}
	
	return M; //the determined molar mass of the compound inputted into function
}<file_sep>#ifndef SNAKEGAME_H
#define SNAKEGAME_H

#include <deque> //needed for the deque to be properly defined

//enum regarding snake direction control
enum snakeDirection { LEFT, RIGHT, UP, DOWN, STOP };

class Snake {
	public:
		Snake (); //default constructor
		//constructor for specified user dimensioss for game play
		Snake (const int requiredWidth, const int requiredHeight, bool warp = true);
		// constructor for specified dimensions and chosen symbols for snake head and tail
		Snake(const int requiredWidth, const int requiredHeight, const char specifiedHead, const char specifiedTail, bool warp = true);
		~Snake(); //destructor
		void edit(); //edit function to change gameplay settings
	
	private:
		//paramters
		bool isGameRunning; //boolean to check is the game still continuing
		bool warpWalls; //boolean to see if the walls should be warped behind each other (go. go from left end of wall to right end of wall)
		int gameWidth; //game area width`
		int gameHeight; //game area height
		snakeDirection direction; //direction of the snake, defined using enums
		int xCoor, yCoor; //x and y coordinates (specifically of the head)
		int levelUpx, levelUpy; //x and y coordinates of the level up food for snake
		int score; //current game score
		int tailLength; //length of the tail
		char snakeHead; //symbol to represent the head
		char snakeTail; //symbol to represent the tail
		//create deque linked lists to store previous coordinates of tail coordinates
		std::deque <int> tailCoordinates[2]; 
		void initialGame(); //method for starting the game up 
		void drawCanvas(); //method for drawing the game
		void keyInput(); //method that checks for keyboard input from user
		void gameWork(); //method that runs over all the logic and game constraints
		void gamePlay(); //keeps the game running, moves frame to frame
};
#endif
<file_sep>#include <iostream>
#include <stdlib.h>
#include "snakeGame.h"
using namespace std;


int main () {
	
	cout << "Would you like to:" << endl; //ask user input regarding game settings
	cout << "   (1) Create your own game" << endl;
	cout << "   (2) Use the default version" << endl;
	int choice;
	cin >> choice;
	
	if (choice == 1) { //user wants to create their own game
		int newWidth = 0;
		int newHeight = 0;
		AskWidth: cout << endl << "What width should your snake game have: ";
		cin >> newWidth;
		if (newWidth < 5) {
			cout << endl << "Sorry, your specified width is too small, try again";
			goto AskWidth;
		}
		AskHeight: cout << "What height should your snake game have: ";
		cin >> newHeight;
		if (newHeight < 5) {
			cout << endl << "Sorry, your specified height is too small, try again";
			goto AskHeight;
		}
		//finished setting game dimesions, onto setting snake features
		cout << endl << "Would you like to change the head of the snake to something else?";
		cout << endl << "\t Current Head Symbol: O\n";
		cout << endl << "Press Y/y to change the symbol, press N/n to keep it the same: ";
		char choice;
		char head = '\0'; //initializing a null character tail to start off
		cin >> choice;
		if (choice == 'y' || choice == 'Y'){
			cout << "Type the symbol (1 character) you choose as your snake head: ";
			cin >> head;
		}
		
		cout << endl << "Would you like to change the tail of the snake to something else?";
		cout << endl << "\t Current Head Symbol: o\n";
		cout << endl << "Press Y/y to change the symbol, press N/n to keep it the same: ";
		char choice2;
		char tail = '\0'; //initializing a null character tail to start off
		cin >> choice2;
		if (choice2 == 'y' || choice2 == 'Y'){
			cout << "Type the symbol (1 character) you choose as your snake tail: ";
			cin >> tail;
		} 
		
		//ask if user wants a boundaryless snake game where walls of snake game are warped around and no restrictions of boundaries
		cout << endl << "How do you want to set up the wall boundaries:";
		cout << "\n\t(1) Warp Around \n\t(2) Be Rigid and no wrapping/warping\n";
		int choice3;
		cin >> choice3;
		
		if (head == '\0' && tail == '\0') { //no unique head or tail chosen
			if (choice3 == 2)
				Snake game (newWidth, newHeight, false);
			else 
				Snake game (newWidth, newHeight);
		} else if (head == '\0') { //unique tail chosen
			if (choice3 == 2)
				Snake game (newWidth, newHeight, 'O', tail, false);
			else 
				Snake game (newWidth, newHeight, 'O', tail);
		} else if (tail == '\0') { //unique head chosen
			if (choice3 == 2)
				Snake game (newWidth, newHeight, head, 'o', false);
			else 
				Snake game (newWidth, newHeight, head, 'o');
		} else { //unique head and tail chosen
			if (choice3 == 2)
				Snake game (newWidth, newHeight, head, tail, false);
			else 
				Snake game (newWidth, newHeight, head, tail);
		}
	} else if (choice == 2) { //user just wants to play default game version
		myGame = new Snake();
	}
	
	gameFinished: return 0;
}
<file_sep>#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <ctype.h>

typedef struct Players {
	//inputted basic statistics
	char name[50]; //first and/or last name of person
	unsigned short int GP; //games played
	unsigned short int goals;
	unsigned short int assists;
	unsigned short int points;
	short int plus_minus;
	unsigned short int shots; //on goal
	unsigned short int PIM; //penalty minutes
	unsigned short int hits; 
	unsigned short int blocked_shots; 
	float faceoff_percent; 
	char ATOI[6]; //average time on ice
	//calculated advanced metrics
	float shot_percent;
	float goals_per_60;
	float assists_per_60;
	float points_per_60;
	float shots_per_60;
	float plus_minus_per_60;
	float PIM_per_game;
	float goal_percentage; //goals account for how much of the total points
	float assist_percentage; //assists account for how much of the total points
	float defensiveness; //a combination of hits and blocked shots combined with games played
} thePlayers, *PlayerStats;

int readFile (const char* tfile);
int calcStats (int PlayerNumber);
int exportData (int Players);

PlayerStats allPlayers; //gloabl scope struct array pointer
int main () {
	printf ("Welcome to Hockey Manager,\nThis program that can be used to filter and sort statistics provided by you.\
	\nYour text file will be read and presented back in a comma separated value file (.csv) for you to analyze\n");
	
	printf ("\nEnter the file name (with .txt extension) you wish to open,\
	\nEnsure it is in the same folder as this program: ");
	char inputFile [50];
	scanf ("%s", inputFile); //attain input file name
	
	int count1 = 0;
	while (inputFile[count1] != '.') //this will find the length of input file
		count1++;
	
	if (inputFile[count1+1] != 't' || inputFile[count1+2] != 'x' || inputFile[count1+3] != 't') {
		printf ("Invalid file name inputted, not a .txt extension");
		return -1;
	}
	
	int people_number = 0; //the number of players that are present in the text file to be analyzed
	
	people_number = readFile (inputFile);
	if (people_number < 0) {
		printf ("An error occurred when reading data, ensure text file has statistics of each person on a separate line\
		\nAlso ensure that each statistic is in order and it is separated by a space(s) or comma(s)\n");
		return -1;
	} else if (people_number == 0) {
		printf ("No data was found in the text file");
	}
	
	if ((calcStats (people_number) != 0)) { //error checking from calcStats function
		printf ("\nAn error occurred during advanced metrics calculations");
		return -1;
	}
	
	if ((exportData(people_number) != 0)) {
		printf ("\nAn error occurred during advanced metrics calculations");
		return -1;
	}
	
	printf ("\n\nFile has been read successfully! Open up HockeyStats.csv to see your new .csv file\n");
	
	return 0;
	
}

int readFile (const char* tfile) {
	int numPpl = 0;
	FILE* FileIN;
	
	FileIN = fopen(tfile, "r");
	if (FileIN == NULL) { //error check to ensure file opened properly
		printf ("Input file could not be opened\n");
		return -1;
	}
		
	char temp[500]; int linecheck;
	while (fgets(temp, 499, FileIN) != NULL) { //take in line by line
		linecheck = 0;
		while (temp[linecheck] != '\n')
			linecheck++;
		if (linecheck == 0) //empty line found
			continue;
		numPpl++; //count up the number of players to have their statistics inputted
	}
	
	clearerr(FileIN); //move back to the beginning to now start inputting tne data
	fseek(FileIN, 0, SEEK_SET);
	
	allPlayers = (PlayerStats) malloc (numPpl*sizeof(thePlayers)); //create appropriate number of structs
	
	int i = 0;
	for ( ; i < numPpl; i++) {
		fscanf(FileIN, "%49s", allPlayers[i].name); //take in the first word (should be a name)
		char temporary[25];
		fscanf(FileIN, "%24s", temporary); //take in the next word assuming it is the last name
		
		//if the first letter is not a character, it means that 2nd word was indeed a statistic, player's name is only 1 word
		if (temporary[0] > 47 && temporary[0] < 58) { 
			int ch = 0;
			while (temporary[ch] != '\0')
				ch++;
			
			fseek (FileIN, -ch, SEEK_CUR); //move back specific number of places according the number of digits
		} else {
			strcat(allPlayers[i].name, " "); //if 2nd word was indeed a character, player has a 2 word name
			strcat(allPlayers[i].name, temporary); // join the 2 words to form one string in the struct
		}
		
		char t;
		t = getc(FileIN);
		while (!isalnum(t) && t!=EOF) //move forward until alphanumeric character seen
			t = getc(FileIN);
		
		if (!isalpha(t)) {
			int x = 0;
			int checker = 1000; //random large number added, will be used to count up char from mins to secs stat
			while (t != ' ' && t != '\n' && t != EOF && x < 5) {
				allPlayers[i].ATOI[x] = t;
				x++;
				t = getc (FileIN);
				if (t == ':') { //check for valid minutes number in ATOI
					checker = x;
					int check_mins = atoi (allPlayers[i].ATOI);
					if (check_mins < 0 || check_mins > 60) {
						printf ("Invalid ATOI minutes for player %d\n", i+1);
						return -1;
					}
				}
				if (x == checker + 2) { //check for valid seconds number in ATOI
					char secs [3];
					memcpy(secs, &allPlayers[i].ATOI[3], 2);
					secs[3] = '\0';
					int check_secs = atoi (secs);
					if (check_secs < 0 || check_secs > 60) {
						printf ("Invalid ATOI minutes for player %d\n", i+1);
						return -1;
					}
				}
			}
			if (x == 0) { //if no ATOI stat found
				memcpy(allPlayers[i].ATOI, "00:00", 5);
			}
			if (x == 2) { //if only ATOI mins found
				allPlayers[i].ATOI[2] = ':';
				allPlayers[i].ATOI[3] = '0';
				allPlayers[i].ATOI[4] = '0';
			}
			allPlayers[i].ATOI[5] = '\0'; //add null character
		} else {
			printf ("\nError: No ATOI stat found, a crucial statistic that is needed");
			return -1;
		}
		
		int num_signed_int = 0;
		int temp[9] = {0}; //temp array to store data from file
		
		for (int structElements = 0; structElements < 9; structElements++) {	
			
			if (fscanf (FileIN, "%d", &temp[structElements]) == 0) //error occurred
				continue;
			
			if ((structElements < 4 || structElements > 4) && structElements < 10) { //error checking for statistic 1-4 and 5-10
				if (temp[structElements] < 0 && temp[structElements] > 65535) {
					printf ("Invalid numbers present in the data provided for player %d, statistics %d", i, structElements);
					return -1;
				}
			}
			
			char separation = fgetc (FileIN); //temp char to filter out separating characters between stat numbers
			while ((separation < '0' || separation > '9') && (separation != '\n' && separation != EOF))
				separation = fgetc (FileIN);
			
			if ((separation == EOF) || separation == '\n') //finish taking in input if EOF or end of line seen
				continue;
			else 
				fseek(FileIN, -1, SEEK_CUR); //move back one character to continue taking in statistics
		}
		
		//error checking to ensure stats entered make sense in the hockey sense
		if ((temp[1] + temp[2] != temp[3]) || (temp[1] > temp[3]) || (temp[2] > temp[3])) {
			printf ("Invalid number of goals/assists/points for player %d, goals+assists = points\n", i+1);
			return -1;
		}
		
		if ((temp[1] > temp[5])) {
			printf ("Invalid number of goals/shots for player %d, goals+assists = points\n", i+1);
			return -1;
		}
		
		allPlayers[i].faceoff_percent = 0; 
		fscanf (FileIN, "%f", &allPlayers[i].faceoff_percent); //directly put in the faceoff_percent value
		if (allPlayers[i].faceoff_percent < 0) {
			printf ("Invalid Faceoff Percentage statistic entered, must be a positive value\n");
		}
		
		//transfer over data from temp integer array to struct data
		allPlayers[i].GP = temp[0]; 
		allPlayers[i].goals = temp[1];
		allPlayers[i].assists = temp[2];
		allPlayers[i].points = temp[3];
		allPlayers[i].plus_minus = temp[4];
		allPlayers[i].shots = temp[5];
		allPlayers[i].PIM = temp[6];
		allPlayers[i].hits = temp[7];
		allPlayers[i].blocked_shots = temp[8];
		
		fseek (FileIN, -1, SEEK_CUR);
		char tem = fgetc (FileIN);
		while (tem != '\n' && tem != EOF) //move past any unneccessary characaters at the end of the line
			tem = fgetc (FileIN);
		
	}
	fclose(FileIN); //close the files
	
	return numPpl; //return the value of the number of people;
} 

int calcStats (int PlayerNumber) {
	float fATOI;
	
	for (int num = 0; num < PlayerNumber; num++) {
		float TOI_mins = 0; //calculating the ATOI stat as a float
		int loc = 0;
		if (allPlayers[num].ATOI[loc] > '0' && allPlayers[num].ATOI[loc] < '6') {
			loc++;
			if (allPlayers[num].ATOI[loc] == ':') { //single minute ATOI
				char temp_ATOI[2]; //a temporary string
				temp_ATOI[0] = allPlayers[num].ATOI[loc-1];
				temp_ATOI[1] = '\0';
				int temporary_ATOI = atoi(temp_ATOI); //get integer vaule of the ATOI minutes
				TOI_mins += (float)temporary_ATOI;
			} else if (allPlayers[num].ATOI[loc] > '0' && allPlayers[num].ATOI[loc] <= '9') { //double digit minute ATOI
				char temp_ATOI2 [3]; //a temporary string for a 2-digit ATOI minute
				memcpy (temp_ATOI2, allPlayers[num].ATOI, 2);
				temp_ATOI2[2] = '\0';
				int temporary_ATOI2 = atoi(temp_ATOI2); //calc the integer value of ATOI in minutes
				TOI_mins += temporary_ATOI2;
				loc++;
			} else 
				break;
			
			loc++;
			char secs_ATOI[3]; //same procedure for calculating ATOI seconds as an integer value from string
			secs_ATOI[0] = allPlayers[num].ATOI[loc];
			loc++;
			secs_ATOI[1] = allPlayers[num].ATOI[loc];
			secs_ATOI[2] = '\0';
			int ATOI_secs = atoi(secs_ATOI); //calculate the integer value of the ATOI seconds
			fATOI = TOI_mins + (float)(ATOI_secs/60.0); //combine mins and secs to form the floating number for ATOi
		} else {
			printf ("Invalid ATOI present\n");
			return -1;
		}
		
		//default parameters for calculated values;
		allPlayers[num].shot_percent = allPlayers[num].points_per_60 = allPlayers[num].shots_per_60 = 0;
		allPlayers[num].goals_per_60 = allPlayers[num].assists_per_60 = allPlayers[num].plus_minus_per_60 = 0;
		allPlayers[num].goal_percentage = allPlayers[num].assist_percentage = 0;
		allPlayers[num].defensiveness  = allPlayers[num].PIM_per_game = 0;
		
		//calculate the different stats from the basic stats inputted for each player, only if they are non-zero
		if (allPlayers[num].points)
			allPlayers[num].points_per_60 = (float)allPlayers[num].points * (60.0/fATOI);
		
		if (allPlayers[num].shots)
			allPlayers[num].shots_per_60 = (float)allPlayers[num].shots * (60.0/fATOI);
		
		if (allPlayers[num].goals) {
			allPlayers[num].goals_per_60 = (float)allPlayers[num].goals * (60.0/fATOI);
			
			if (allPlayers[num].points)
				allPlayers[num].goal_percentage = ((float)allPlayers[num].goals)/((float)allPlayers[num].points) * 100.0;
			
			if (allPlayers[num].shots)
				allPlayers[num].shot_percent = ((float)allPlayers[num].goals)/((float)allPlayers[num].shots) * 100.0;
		}
		
		if (allPlayers[num].assists) {
			allPlayers[num].assists_per_60 = (float)allPlayers[num].assists * (60.0/fATOI);
			
			if (allPlayers[num].points)
				allPlayers[num].assist_percentage = ((float)allPlayers[num].assists)/((float)allPlayers[num].points) * 100.0;
			
		}
		
		if (allPlayers[num].plus_minus)
			allPlayers[num].plus_minus_per_60 = (float)allPlayers[num].plus_minus * (60.0/fATOI);
		
		if (allPlayers[num].GP) {
			if (allPlayers[num].PIM)
				allPlayers[num].PIM_per_game = ((float)allPlayers[num].PIM) / ((float)allPlayers[num].GP);
			
			if (allPlayers[num].hits || allPlayers[num].blocked_shots) //only one of them has to be non-zero since this is just addition
				allPlayers[num].defensiveness = ((float)(allPlayers[num].hits + allPlayers[num].blocked_shots)) / ((float)allPlayers[num].GP);
		}
		
	}
	
	return 0;
}

int exportData (int Players) {
	FILE* csvFile;
	csvFile = fopen ("HockeyStats.csv", "w");
	
	//print the top row, all headers for the statistics
	fputs("Name,Goals,Assists,Points,+/-,Shots,PIM,Hits,Blocks,F%,ATOI,\
	S%,Goals/60,Assists/60,Points/60,Shots/60,+/- /60,PIM/game,G%,A%,Def,\n",csvFile);
	
	//print out all the stats of each player, floats reduced to 2 decimal place
	// "'" added in front of ATOI to avoid Excel from convertin to time/date format
	for (int e = 0; e < Players; e++) {
		int safety = 0;
		safety = fprintf(csvFile, "%s,%d,%d,%d,%d,%d,%d,%d,%d,%.2f%,'%s,%.2f,%.2f,%.2f,%.2f,%.2f,%.2f,%.2f,%.2f,%.2f,%.2f,\n",\
		allPlayers[e].name,allPlayers[e].goals,allPlayers[e].assists,allPlayers[e].points,allPlayers[e].plus_minus,\
		allPlayers[e].shots,allPlayers[e].PIM,allPlayers[e].hits,allPlayers[e].blocked_shots,\
		allPlayers[e].faceoff_percent,allPlayers[e].ATOI,allPlayers[e].shot_percent,\
		allPlayers[e].goals_per_60,allPlayers[e].assists_per_60,allPlayers[e].points_per_60,\
		allPlayers[e].shots_per_60,allPlayers[e].plus_minus_per_60,allPlayers[e].PIM_per_game,\
		allPlayers[e].goal_percentage,allPlayers[e].assist_percentage,allPlayers[e].defensiveness);
		if (safety < 0){
			printf ("\nAn error occured when exporting the data, check your permission settings\n");
			return -1;
		}
	}
	
	fclose(csvFile);
	free(allPlayers);
	
	return 0;
}<file_sep># Side-Projects

This repo is just a collection of the mini projects I worked on as a beginner software developer on my own time. The projects have mostly been completed in C and C++; to view more Python related projects, visit the Python-Projects repository.

## Major Projects

### Molar Mass Calculator

A scientific calculator coded in C language that accurately calculates the molar mass of elements and compounds

### 2048 Game

A fun 2048 game I created in C language to explore command line game creation

### Hockey Statistics Program

A hockey statistics program that can be used as data storage and exportation as well as data analysis of basic hockey statistics

### Group Organizer

A small database system I created for data organization and management

### Snake

A fun snake game created in C++ and to be run on the command line. Created fully with object-oriented programming<file_sep>#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>

typedef struct Person {
	char firstName[20];
	char midInitial;
	char lastName[20];
	int age;
	char city[20];
	char country[20];
	struct Person* next; //the struct pointer for the next item in the list
}People, *thePeople;

void print ();
int read ();
int read(const char* iFile);
void swap (thePeople temporary1, thePeople temporary2);
int compare(char* str1, char* str2);
void sort (int selection);
void reverse ();
void writing();

thePeople head; //struct pointer for the first struct, global scope to keep it accessible in all functions
int Ppl = 0;; //global scope integer for how many people exist within the linked list

int main() {
	DataEntering: printf("How would you like to enter the data?\n");
	printf("\t(1) Manually\n \t(2) Through a text file\n");
	
	int choice;
	scanf("%i", &choice);
	if (choice == 1) {
		if (read()){
			printf ("\nAn error occurred while inputting data manually\n");
			return -1;
		}
	} else if (choice == 2) {
		printf ("\nEnter the text file with extension (.txt)\n");
		printf ("Ensure that all 6 fields are entered in the text file, \
		\nif information is not present for a specific field, enter a '-' within that field:\n");
		char givenFile[50];
		scanf ("%s", givenFile);
		if (read (givenFile)) {
			printf ("\nAn error occurred when reading the file\n");
			return -1;
		} else 
			printf ("\nData has been read:");
	} else {
		printf ("Sorry wrong choice entered, try again");
		goto DataEntering;
	}
	
	print();
	
	AskOrder: puts("\n\nDo you want to order this data according to a specific field(y/n): ");
	char order = 0;
	scanf (" %c", &order);
	
	if (order == 'y') {
		Ordering: puts("\nAccording to what field would like the data sorted:");
		puts("\n\t(1) First Name \n\t(2) Middle Initial \n\t(3) Last Name \n\t(4) Age \n\t(5) City \n\t(6) Country\n");
		int choice2;
		scanf ("%i", &choice2);
		sort(choice2);
	} else if (order == 'n') {
		printf ("\nData has been kept the same");
		goto nextStep;
	} else if (order == 'q') 
		return -1;
	else {
		puts ("\nWrong input entered, try again");
		goto AskOrder;
	}
	nextStep: print();
	
	AskReverse: puts("\n\nWould you like it sorted in the opposite matter (descending)(y/n): ") ;
	char opposite = 0;
	scanf (" %c", &opposite);
	
	if (opposite == 'y')
		reverse();
	else if (opposite == 'n') {
		printf ("\nData has been kept the same");
		goto lastStep;
	} else {
		puts ("\nWrong input has been entered, try again");
		goto AskReverse;
	}
	
	print();
	
	
	
	lastStep: puts ("\nWould you like this data transfered into a csv file?(y/n)");
	char choice3 = 0;
	scanf(" %c", &choice3);
	if (choice3 == 'y') {
		writing();
	} else if (choice3 == 'n')
		return 0;
	else {
		puts ("An incorrect choice was entered, try again");
		goto lastStep;
	}

	return 0;
}

void print () {
	thePeople toPrint = head;
	for (int reading = 0; reading < Ppl; reading++) {
		printf ("\nPerson %i: %s %c %s %i %s %s", reading+1, toPrint->firstName,\
		toPrint->midInitial, toPrint->lastName, toPrint->age, toPrint->city, toPrint->country);
		toPrint = toPrint->next;
		if (toPrint == NULL)
			break;
	}
}

int read () {
	int key = 65;
	puts ("Press Esc to finish inputting information\n");
	int attain_info = 0;
	head = (thePeople) malloc(sizeof(People)); //create one struct to begin with
	thePeople input = head;

	int check = 0; //a checker to know that every time a new person is made, new memory is used
	int maxL = 19; //the max length of any of the strings
	do {
		attain_info = attain_info % 6; //asking for the right information in the right order
		switch (attain_info) {
			case 0: 
				if(check){
					Ppl++;
					thePeople newPerson = (thePeople) malloc(sizeof(People));
					input->next = newPerson;
					newPerson->next = NULL;
					input = newPerson;
				}
				printf("\n\nPerson %d\n", Ppl+1);
				puts ("Enter the first name: ");
				for (int j = 0; j < maxL-1; j++) {
					key = getch();
					if (key == 27 || key == 3) //escape or CtrC pressed
						goto inputEnded;
					else if (key == 13) { //new line char seen
						input->firstName[j] = 0;
						break;
					} else if (key == 8){ //if backspace is asked for
						input->firstName[j-1] = 0;
						j-=2;
						printf("\n%s", input->firstName);
						continue;
					}
					input->firstName[j] = key;
					printf ("%c", key);
				}
				break;
			case 1: 
				puts("\nEnter the middle initial: ");
				key = getch();
				if (key == 27 || key == 3) //escape or Ctr+C pressed
					goto inputEnded;
				printf ("%c", key);
				input->midInitial = key;
				break;
			case 2:
				puts("\nEnter the last name: ");
				for (int k = 0; k < maxL-1; k++) {
					key = getch();
					if (key == 27 || key == 3) //escape or CtrC pressed
						goto inputEnded;
					else if (key == 13) { //new line char seen
						input->lastName[k] = 0;
						break;
					} else if (key == 8){ //if backspace is asked for
						input->lastName[k-1] = 0;
						k-=2;
						printf("\n%s", input->lastName);
						continue;
					}
					input->lastName[k] = key;
					printf ("%c", key);
				}
				break;
			case 3:  {
				puts ("\nEnter their age: ");
				int numb = 0;
				key = getch();
				for (int l = 0; l < 3; l++) {
					if (!isdigit(key) && key != 8 && key != 13) {
						goto inputEnded;
						input->age = numb;
					}
					if (key == 8){
						l -=2;
						numb /= 10;
						printf ("\n%i", numb);
						key = getch();
						continue;
					} else if (key == 13) { //new line char seen
						break;
					}
					printf ("%c", key);
					numb = numb*10 + (key-48);
					key = getch();
				}
				input->age = numb;
				break; }
			case 4: 
				puts("\nEnter their city: ");
				for (int m = 0; m < maxL-1; m++) {
					key = getch();
					if (key == 27 || key == 3) //escape or CtrC pressed
						goto inputEnded;
					else if (key == 13) { //new line char seen
						input->city[m] = 0;
						break;
					} else if (key == 8){ //if backspace is asked for
						input->city[m-1] = 0;
						m-=2;
						printf("\n%s", input->city);
						continue;
					}
					input->city[m] = key;
					printf ("%c", key);
				}
				break;
			case 5:
				puts("\nEnter their country: ");
				for (int n = 0; n < maxL-1; n++) {
					key = getch();
					if (key == 27 || key == 3) //escape or CtrC pressed
						goto inputEnded;
					else if (key == 13) { //new line char seen
						input->country[n] = 0;
						break;
					} else if (key == 8){ //if backspace is asked for
						input->country[n-1] = 0;
						n-=2;
						printf("\n%s", input->country);
						continue;
					}
					input->country[n] = key;
					printf ("%c", key);
				}
				check = 1;
				break;
			default:
				printf ("\nAn error occurred during importing data");
				return -1;
				break;
		}
		attain_info++;
	} while (key != 27 && key != 3);
	inputEnded: return 0;	
}

int read(const char* iFile) { //reading the file if provided
	FILE* OpenFile;
	OpenFile = fopen(iFile, "r");

	if (OpenFile == NULL) { //error check to ensure file opened properly
		printf ("Input file was not opened\n");
		return -1;
	}
		
	char temp[150];
	int linechar;

	while (fgets(temp, 149, OpenFile) != NULL) { //take in line by line
		linechar = 0;
		while (temp[linechar] != '\n') {
			linechar++;
			if (isalnum(temp[linechar]))
				break;
		}
		if (linechar == 0) //empty line found
			continue;
		Ppl++; //count up the number of players to have their statistics inputted
	}
	clearerr(OpenFile); //move back to the beginning to now start inputting tne data
	fseek(OpenFile, 0, SEEK_SET);

	head = (thePeople) malloc(sizeof(People)); //create one struct to begin with
	thePeople cursor = head;
	for (int in = 0; in < Ppl; in++) {
		if (in) {
			thePeople temp = (thePeople) malloc(sizeof(People));
			cursor->next = temp;
			temp->next = NULL;
			cursor = temp;
		}
		
		linechar = 0;
		char t;
		cursor->firstName[0] = cursor->midInitial = cursor->lastName[0] = cursor->city[0] = cursor->country[0] = 0;
		cursor->age = 0;
		
		t = getc(OpenFile);
		while (!isalnum(t) && t != EOF && t != '-') //move forward until alphanumeric character seen
			t = getc(OpenFile);
		fseek(OpenFile, -1, SEEK_CUR);
		fscanf(OpenFile, "%19s", cursor->firstName);
		
		t = getc(OpenFile);
		while (!isalnum(t) && t != EOF && t != '-') //move forward until alphanumeric character seen
			t = getc(OpenFile);
		fseek(OpenFile, -1, SEEK_CUR);
		fscanf(OpenFile, "%c", &cursor->midInitial);
		
		t = getc(OpenFile);
		while (!isalnum(t) && t != EOF && t != '-') //move forward until alphanumeric character seen
			t = getc(OpenFile);
		fseek(OpenFile, -1, SEEK_CUR);
		fscanf(OpenFile, "%19s", cursor->lastName);
		
		t = getc(OpenFile);
		while (!isdigit(t) && t != EOF && t != '-')
			t = getc(OpenFile);
		if (t == '-')
			cursor->age = 0;
		else {
			for (int digits = 0; digits < 3; digits++) {
				cursor->age = 10*cursor->age + (t - 48);
				t = getc(OpenFile);
				if (!isdigit(t))
					break;
			}
		}
		
		t = getc(OpenFile);
		while (!isalnum(t) && t != EOF && t != '-') //move forward until alphanumeric character seen
			t = getc(OpenFile);
		fseek(OpenFile, -1, SEEK_CUR);
		fscanf(OpenFile, "%19s", cursor->city);
		
		t = getc(OpenFile);
		while (!isalnum(t) && t != EOF && t != '-') //move forward until alphanumeric character seen
			t = getc(OpenFile);
		fseek(OpenFile, -1, SEEK_CUR);
		fscanf(OpenFile, "%19s", cursor->country);
	}

	return 0;	
}

void swap (thePeople person1, thePeople person2) {
	if (person1 == head) { //swapping the head and the 2nd item in the list
		thePeople swap = head->next->next;
		head = head->next;
		head->next = person1;
		person1->next = swap;
	} else { //changing past the head
		thePeople swap = person1->next;
		person1->next = person1->next->next;
		swap->next = person1;
		person2->next = swap;
	}
}

int compare(char* str1, char* str2) {
		int i = 0;
		while (i < 19) { //max string length
			int r1 = str1[i]; //take in ASCII vaues of characters and put them into an integer
			int r2 = str2[i]; 
		
			if (r1 > 96 && r1 < 123) //see if the first integer represents a lowercase letter
				r1 -= 32; //turn it into a capital letter
			if (r2 > 96 && r2 < 123) //see if the second integer represents a lowercase letter
				r2 -= 32; //turn it into a capital letter
		
			if (r1 < r2) //compare the two integers
				return -1;
			if (r1 > r2)
				return 1;
		
			if (r1 == '\0' && r2 == '\0') //if both elements end at the same letter and were common for the rest of the characters, they are same names
				return 0;
			if (r1 == '\0') //if first one was equal and shorter, it should be ahead
				return -1;
			if (r2 == '\0') //if second one was equal and shorter, it should be ahead
				return 1;
			i++;
		}
	return 0;
}

void sort (int selection) {
	switch (selection){
		case 1: 
			for (int loops = 0; loops < Ppl-1; loops++) {
				for (int iter = 0; iter < Ppl-1-loops; iter++) {
					thePeople temporary1 = head;
					thePeople temporary2;
					for (int list = 0; list < iter; list++) {
						if (list == (iter - 1)) //remember the item before the current item in case of swap
							temporary2 = temporary1;
						temporary1 = temporary1->next;
					}
					if (compare(temporary1->firstName, temporary1->next->firstName) > 0)
						swap (temporary1, temporary2);
					else if (compare(temporary1->firstName, temporary1->next->firstName) == 0) {
						if (temporary1->midInitial > temporary1->next->midInitial)
							swap(temporary1, temporary2);
						else if (temporary1->midInitial == temporary1->next->midInitial) {
							if (compare(temporary1->lastName, temporary1->next->lastName) > 0)
								swap(temporary1, temporary2);
						}
					}
				}
			}
			break;
		case 2: 
			for (int loops = 0; loops < Ppl-1; loops++) {
				for (int iter = 0; iter < Ppl-1-loops; iter++) {
					thePeople temporary1 = head;
					thePeople temporary2;
					for (int list = 0; list < iter; list++) {
						if (list == (iter - 1)) //remember the item before the current item in case of swap
							temporary2 = temporary1;
						temporary1 = temporary1->next;
					}
					if (temporary1->midInitial > temporary1->next->midInitial)
						swap (temporary1, temporary2);
					else if (temporary1->midInitial == temporary1->next->midInitial) {
						if (compare(temporary1->firstName, temporary1->next->firstName) > 0)
							swap(temporary1, temporary2);
						else if (compare(temporary1->firstName, temporary1->next->firstName) == 0) {
							if (compare(temporary1->lastName, temporary1->next->lastName) > 0)
								swap(temporary1, temporary2);
						}
					}
				}
			}
			break;
		case 3: 
			for (int loops = 0; loops < Ppl-1; loops++) {
				for (int iter = 0; iter < Ppl-1-loops; iter++) {
					thePeople temporary1 = head;
					thePeople temporary2;
					for (int list = 0; list < iter; list++) {
						if (list == (iter - 1)) //remember the item before the current item in case of swap
							temporary2 = temporary1;
						temporary1 = temporary1->next;
					}
					if (compare(temporary1->lastName, temporary1->next->lastName) > 0)
						swap (temporary1, temporary2);
					else if (compare(temporary1->lastName, temporary1->next->lastName) == 0) {
						if (compare(temporary1->firstName, temporary1->next->firstName) > 0)
								swap(temporary1, temporary2);
						else if (compare(temporary1->firstName, temporary1->next->firstName) == 0) {
							if (temporary1->midInitial > temporary1->next->midInitial)
								swap(temporary1, temporary2);	
						}
					}
				}
			}
			break;
		case 4: 
			for (int sets = 0; sets < Ppl-1; sets++) {
				for (int reps = 0; reps < Ppl-1-sets; reps++){
					thePeople temporary1 = head;
					thePeople temporary2;
					for (int list = 0; list < reps; list++) {
						if (list == (reps - 1)) //remember the item before the current item in case of swap
							temporary2 = temporary1;
						temporary1 = temporary1->next;
					}
					if (temporary1->age > temporary1->next->age)
						swap(temporary1, temporary2);
				}
			}
			break;
		case 5: 
			for (int loops = 0; loops < Ppl-1; loops++) {
				for (int iter = 0; iter < Ppl-1-loops; iter++) {
					thePeople temporary1 = head;
					thePeople temporary2;
					for (int list = 0; list < iter; list++) {
						if (list == (iter - 1)) //remember the item before the current item in case of swap
							temporary2 = temporary1;
						temporary1 = temporary1->next;
					}
					if (compare(temporary1->city, temporary1->next->city) > 0)
						swap (temporary1, temporary2);
					else if (compare(temporary1->city, temporary1->next->city) == 0) {
						if (compare(temporary1->country, temporary1->next->country) > 0)
							swap(temporary1, temporary2);
					}
				}
			}
			break;
		case 6: 
			for (int loops = 0; loops < Ppl-1; loops++) {
				for (int iter = 0; iter < Ppl-1-loops; iter++) {
					thePeople temporary1 = head;
					thePeople temporary2;
					for (int list = 0; list < iter; list++) {
						if (list == (iter - 1)) //remember the item before the current item in case of swap
							temporary2 = temporary1;
						temporary1 = temporary1->next;
					}
					if (compare(temporary1->country, temporary1->next->country) > 0)
						swap (temporary1, temporary2);
					else if (compare(temporary1->country, temporary1->next->country) == 0) {
						if (compare(temporary1->city, temporary1->next->city) > 0)
							swap(temporary1, temporary2);
					}
				}
			}
			break;
		default:
			puts ("\nSorry wrong choice entered, try again\n");
			return;
	}
}

void reverse () {//copies over all the struct pointers into an array and then reverses the list order
	thePeople* copied;
	copied = (thePeople*) malloc(Ppl*sizeof(thePeople)); //create array of struct pointers on heap

	thePeople organize = head;
	int items = 0;
	
	while (organize != NULL) {
		copied[items] = organize;
		organize = organize->next;
		items++;
		if (items > Ppl) {
			printf ("\nAn error occured during the reverse function");
			return;
		}
	}
	
	head = copied[Ppl-1];//last item in the struct becomes head
	thePeople reverser = head; //new temp struct pointer used to traverse list and change order
	
	for (int a = 0; a < Ppl-1; a++) {
		reverser->next = copied[Ppl-2-a]; //start reversing order
		reverser = reverser->next;
	}
	reverser->next = NULL; //originally the head of the list, now the end of the list
}

void writing () {
	FILE* writeFile;
	writeFile = fopen("groupOrganizer.csv", "w");
	
	thePeople exporting = head;
	for (int writing = 0; writing < Ppl; writing++) {
		fprintf (writeFile, "Person %i: ,%s ,%c ,%s ,%i ,%s ,%s\n", writing+1, exporting->firstName,\
		exporting->midInitial, exporting->lastName, exporting->age, exporting->city, exporting->country);
		exporting = exporting->next;
		if (exporting == NULL)
			break;
	}
	
	fclose(writeFile);
}<file_sep>#include <stdio.h>
#include <conio.h>
#include <stdlib.h>

void printArea (int values[4][4]);
void shiftLeft (int themValues[4][4]);
void shiftRight (int themValues[4][4]);
void shiftUp (int themValues[4][4]);
void shiftDown (int themValues[4][4]);
int addNumber(int themValues[4][4]);
int possibleMoves (int themValues[4][4]);

int main () {
	system ("cls"); //clear screen for game to be presented
	int box[4][4] = {0}; //initally game box is all zeroes
	addNumber(box); //add a random number to the box
	
	printf ("\nWELCOME TO A FUN GAME OF 2048!!\n\n\n");
	printf ("\t\t\t\t  A game created by <NAME>\n");
	printArea(box); //print box
	
	int keyboardInput;
	int secondInput;
	int invalid = 0;
	printf ("\nPress Esc or 'Q' to exit game\nEnter your next move (Left/Right/Up/Down)\n");
	
	while ((keyboardInput = _getch()) != 27 && keyboardInput != 81 && keyboardInput != 113 && keyboardInput != 3) { //continue until escape button is not hit
		if (keyboardInput == 97 || keyboardInput == 65) { // 'a' or 'A' button
			system ("cls");
			shiftLeft(box);
		} else if (keyboardInput == 100 || keyboardInput == 68) { // 'D' button
			system ("cls");
			shiftRight(box);
		} else if (keyboardInput == 119 || keyboardInput == 87) { // 'W' button
			system ("cls");
			shiftUp(box);
		} else if (keyboardInput == 115 || keyboardInput == 83) { // 'S' button
			system ("cls");
			shiftDown(box);
		} else if (keyboardInput == 224) { // If inputs are from arrow kee
			secondInput = _getch();
			if (secondInput == 75) { // Left arrow key
				system ("cls");
				shiftLeft(box);
			} else if (secondInput == 77) { // Right arrow key
				system ("cls");
				shiftRight(box);
			} else if (secondInput == 72) { // Up arrow key
				system ("cls");
				shiftUp(box);
			} else if (secondInput == 80) { // Down arrow key
				system ("cls");
				shiftDown(box);
			} else {
				system("cls");
				invalid = 1;
			}
		} else  {
			system("cls");
			invalid = 1;
		}
		
		if (invalid != 1) {
			int point = addNumber(box);
			int point2 = possibleMoves(box);
			
			if (point < 0 && point2 < 0) {
				printArea(box);
				printf ("\n\nGame over, no more possible moves");
				break;
			}
		}
		
		printf ("\nWELCOME TO A FUN GAME OF 2048!!\n\n\n");
		printf ("\t\t\t\t  A game created by <NAME>\n");
		printArea(box);
		printf("\nPress Esc or 'Q' to exit game\nEnter your next move (Left/Right/Up/Down)\n");
		
		if (invalid == 1) {
			printf ("\n\nInvalid move, check your keys and try again\n\n");
		}
	}
	
	printf ("\n\nHope you had fun playing!\n\n");
	
}

void printArea (int values[4][4]) {
	for (int a = 0; a < 65; a++) {
			printf ("-");
	}
	
	printf ("\n");
	
	for (int i = 0; i<4; i++) {
		for (int j = 0; j<4; j++) {
			if (values[i][j] == 0) 
				printf ("|\t\t");
			else {
				if (values[i][j] < 100)
					printf ("|\t%d\t", values[i][j]);
				else if (values[i][j] < 1000)
					printf ("|      %d      ", values[i][j]);	
				else 
					printf ("|      %d     ", values[i][j]);	
		}
		}
		printf ("|");
		printf ("\n");
		for (int k = 0; k < 65; k++) {
			printf ("-");
		}
		printf ("\n");
	}
}

void shiftLeft (int themValues[4][4]) {
	for (int z = 0; z < 4; z++) { // move if empty space exists
		for (int y = 0; y < 3; y++) {
			if (themValues[z][y] == 0) {
				
				if (y<2 && themValues[z][y+1] == 0) {
					if (y<1 && themValues[z][y+2] == 0) {
						themValues[z][y] = themValues[z][y+3];
						themValues[z][y+3] = 0;
					} else {
					themValues[z][y] = themValues[z][y+2];
					themValues[z][y+2] = 0;
					}
				} else {
				themValues[z][y] = themValues[z][y+1];
				themValues[z][y+1] = 0;
				}
				if (y < 2) {
					themValues[z][y+1] = themValues[z][y+2];
					themValues[z][y+2] = 0;
				}
				if (y < 1) {
					themValues[z][y+2] = themValues[z][y+3];
					themValues[z][y+3] = 0;
				}
			}
		}
	}
		
	for (int c = 0; c < 4; c++) { // move if common numbers exist
		for (int d = 0; d < 3; d++) {
			if (themValues[c][d] == themValues[c][d+1]) {
				themValues[c][d] += themValues[c][d+1];
				themValues[c][d+1] = 0;
				if (d < 2) {
					themValues[c][d+1] = themValues[c][d+2];
					themValues[c][d+2] = 0;
				}
				if (d < 1) {
					themValues[c][d+2] = themValues[c][d+3];
					themValues[c][d+3] = 0;
				}
				
			}
		}
	}
}

void shiftRight (int themValues[4][4]) {
	for (int z = 0; z < 4; z++) { // move if empty space exists
		for (int y = 3; y > 0; y--) {
			if (themValues[z][y] == 0) {
				if (y>1 && themValues[z][y-1] == 0) {
					if (y>2 && themValues[z][y-2] == 0) {
						themValues[z][y] = themValues[z][y-3];
						themValues[z][y-3] = 0;
					} else {
					themValues[z][y] = themValues[z][y-2];
					themValues[z][y-2] = 0;
					}
				} else {
				themValues[z][y] = themValues[z][y-1];
				themValues[z][y-1] = 0;
				}
				if (y > 1) {
					themValues[z][y-1] = themValues[z][y-2];
					themValues[z][y-2] = 0;
				}
				if (y > 2) {
					themValues[z][y-2] = themValues[z][y-3];
					themValues[z][y-3] = 0;
				}
			}
		}
	}
		
	for (int c = 0; c < 4; c++) { // move if common numbers exist
		for (int d = 3; d > 0; d--) {
			if (themValues[c][d] == themValues[c][d-1]) {
				themValues[c][d] += themValues[c][d-1];
				themValues[c][d-1] = 0;
				if (d > 1) {
					themValues[c][d-1] = themValues[c][d-2];
					themValues[c][d-2] = 0;
				}
				if (d > 2) {
					themValues[c][d-2] = themValues[c][d-3];
					themValues[c][d-3] = 0;
				}
				
			}
		}
	}
}

void shiftUp (int themValues[4][4]) {
	for (int z = 0; z < 3; z++) { // move if empty space exists
		for (int y = 0; y < 4; y++) {
			if (themValues[z][y] == 0) {
				
				if (z<2 && themValues[z+1][y] == 0) {
					if (z<1 && themValues[z+2][y] == 0) {
						themValues[z][y] = themValues[z+3][y];
						themValues[z+3][y] = 0;
					} else {
					themValues[z][y] = themValues[z+2][y];
					themValues[z+2][y] = 0;
					}
				} else {
				themValues[z][y] = themValues[z+1][y];
				themValues[z+1][y] = 0;
				}
				if (z < 2) {
					themValues[z+1][y] = themValues[z+2][y];
					themValues[z+2][y] = 0;
				}
				if (z < 1) {
					themValues[z+2][y] = themValues[z+3][y];
					themValues[z+3][y] = 0;
				}
			}
		}
	}
		
	for (int c = 0; c < 3; c++) { // move if common numbers exist
		for (int d = 0; d < 4; d++) {
			if (themValues[c][d] == themValues[c+1][d]) {
				themValues[c][d] += themValues[c+1][d];
				themValues[c+1][d] = 0;
				if (c < 2) {
					themValues[c+1][d] = themValues[c+2][d];
					themValues[c+2][d] = 0;
				}
				if (c < 1) {
					themValues[c+2][d] = themValues[c+3][d];
					themValues[c+3][d] = 0;
				}
				
			}
		}
	}
}

void shiftDown (int themValues[4][4]) {
	for (int z = 3; z > 0; z--) { // move if empty space exists
		for (int y = 0; y < 4; y++) {
			if (themValues[z][y] == 0) {
				if (z>1 && themValues[z-1][y] == 0) {
					if (z>2 && themValues[z-2][y] == 0) {
						themValues[z][y] = themValues[z-3][y];
						themValues[z-3][y] = 0;
					} else {
					themValues[z][y] = themValues[z-2][y];
					themValues[z-2][y] = 0;
					}
				} else {
				themValues[z][y] = themValues[z-1][y];
				themValues[z-1][y] = 0;
				}
				if (z > 1) {
					themValues[z-1][y] = themValues[z-2][y];
					themValues[z-2][y] = 0;
				}
				if (z > 2) {
					themValues[z-2][y] = themValues[z-3][y];
					themValues[z-3][y] = 0;
				}
			}
		}
	}
		
	for (int c = 3; c > 0; c--) { // move if common numbers exist
		for (int d = 0; d < 4; d++) {
			if (themValues[c][d] == themValues[c-1][d]) {
				themValues[c][d] += themValues[c-1][d];
				themValues[c-1][d] = 0;
				if (c > 1) {
					themValues[c-1][d] = themValues[c-2][d];
					themValues[c-2][d] = 0;
				}
				if (c > 2) {
					themValues[c-2][d] = themValues[c-3][d];
					themValues[c-3][d] = 0;
				}
				
			}
		}
	}
}

int addNumber(int themValues[4][4]) {
	int rows = rand() % 4;
	int columns = rand() % 4;
	int numAdd = ((rand() % 2)*2)+2;
	int optout = 0;
	
	
	if (themValues[rows][columns] == 0) 
		themValues[rows][columns] = numAdd;
	else {
		for (int ch1 = 0; ch1 < 4; ch1++){
			for (int ch2 = 0; ch2 < 4; ch2++){
				if (themValues[ch1][ch2] == 0)
					optout = 1;
			}
		}
		if (optout == 1)
			addNumber(themValues);
		else {
			return -1;
		}
	}
	return 0;
}

int possibleMoves (int themValues[4][4]) {
	int allow = 0;
	
	for (int q = 0; q < 4; q++) {
		for (int r = 0; r < 3; r++) {
			if (themValues[q][r] == themValues[q][r+1]){
				allow = 1;
				break; break;
			}
		}
	}
	
	for (int s = 0; s < 3; s++) {
		for (int t = 0; t < 4; t++) {
			if (themValues[s][t] == themValues[s+1][t]) {
				allow = 1;
				break;break;
			}
		}
	}
	
	if (allow == 1)
		return 0;
	else
		return -1;
}<file_sep>#include <iostream>
#include <stdlib.h>
#include <conio.h>
#include <time.h>
#include <deque>
#include "snakeGame.h"
using namespace std;


void Snake:: initialGame() {
	//start tje game at halt posiiton
	isGameRunning = true;
	direction = STOP;
	//initial snake coordinates
	xCoor = gameWidth / 4;
	yCoor = gameHeight / 4;
	
	//initial fruit coordinates
	srand(time(NULL)); //use seeds to ensure that truly random values are generated
	levelUpx = rand() % gameWidth;
	levelUpy = rand() % gameHeight;
	
	score = 0;
}

void Snake::drawCanvas(){
	cout << "  "; //draw upper boundary
	for (int i = 0; i < gameWidth+1; i++) {
		cout << "--";
	}
	
	cout << "-" << endl; //compensation character for right corner
	
	for (int k = 0; k < gameHeight; k++) { //drawing the 2nd to n-1 rows of the game
		for (int l = 0; l < 2*gameWidth; l++) {
			if (l == 0 || l == 2*gameWidth-1)
				cout << "  |"; //left boundary
			
			if (k == yCoor && l == xCoor)
				cout << snakeHead; //draw snakehead if coordinates match
			else if (l == levelUpx && k == levelUpy)
				cout << "F"; //draw levelup symbol if coordinates match
			else {
				bool printedTail = false;
				for (int b = 0; b < tailLength; b++) {
					if (tailCoordinates[0][b] == l && tailCoordinates[1][b] == k) {
						cout << snakeTail; //draw snaketail if coordinates match
						printedTail = true;
					}
				}
				if (!printedTail)
					cout << " ";
			}
		}
		cout << endl;
	}
	cout << "  "; //drawing lower boundary/wall
	for (int j = 0; j < gameWidth+1; j++) {
		cout << "--";
	}
	cout << "-" << endl;
	
	cout << "Score: " << score; //display score
}

void Snake::keyInput () {
	if (_kbhit()) {
		switch (_getch()) {
			case 97: //capital letter A
			case 65: //lowercase letter a
				direction = LEFT;
				break;
			case 100: //capital letter D
			case 68: //lowercase letter d
				direction = RIGHT;
				break;
			case 119: //capital letter W
			case 87: //lowercase letter w
				direction = UP;
				break;
			case 115: //capital letter S
			case 83: //lowercase letter s
				direction = DOWN;
				break;
			case 224: //arrow key inputs are used
				switch (_getch()) {
					case 75:
						direction = LEFT;
						break;
					case 77:
						direction = RIGHT;
						break;
					case 72:
						direction = UP;
						break;
					case 80:
						direction = DOWN;
						break;
					default:
						cout << endl << "Wrong key is being pressed" << endl;
						break;
				}
				break;
			case 27: //end program buttons
			case 81: //include Esc, 'q', Q, Ctr+C 
			case 113:
			case 3: 
				isGameRunning = false;
				break;
			case 9: //tab key, wanting to change game settings
				edit();
				break;
		}
	} else 
		return;
}

void Snake::gameWork () {
	if (xCoor == levelUpx && yCoor == levelUpy) { //if snake moves over the level up icon
		score += 10;
		srand(time(NULL));
		tailCoordinates[0].push_front(xCoor); //add one more to the tail coordinates
		tailCoordinates[1].push_front(yCoor);
		levelUpx = rand() % gameWidth; //get a new location for level up icon
		levelUpy = rand() % gameHeight;
		tailLength++;
	} else {
		tailCoordinates[0].push_front(xCoor); //keep adding the latest coordinate to tail coordintaes
		tailCoordinates[1].push_front(yCoor); //this is the snake head that now becomes the first tail
		tailCoordinates[0].pop_back(); //remove the coordinates for the last tail section
		tailCoordinates[1].pop_back();		
	}
	
	switch(direction) { //what direction the snake is moving in
		case LEFT: 
			xCoor--;
			break;
		case RIGHT:
			xCoor++;
			break;
		case UP:
			yCoor--;
			break;
		case DOWN:
			yCoor++;
			break;
		default:
			break;
	}
	if (xCoor >= 2*gameWidth-1) { //boundary conditions depending on whether warping from one side of the wall to the other is allowed
		warpWalls ? xCoor = 0 : isGameRunning = false;
	} else if (xCoor < 0) {
		warpWalls ? xCoor = 2*gameWidth-2 : isGameRunning = false;
	} if (yCoor >= gameHeight) {
		warpWalls ? yCoor = 0 : isGameRunning = false;
	} else if (yCoor < 0) {
		warpWalls ? yCoor = gameHeight : isGameRunning = false;
	}
		
	for (int c = 0; c < tailLength; c++) { //if the snake head runs into the snake tail
		if (tailCoordinates[0][c] == xCoor && tailCoordinates[1][c] == yCoor)
			isGameRunning = false;
	}
	
}

void Snake::gamePlay() {
	while (isGameRunning) {
		system("cls"); //clear console screen for snake game window to appear
		cout << endl << "  A CLASSIC GAME OF SNAKE" << endl << endl;
		for (int i = 0; i < gameWidth/12; i++)
			cout << "\t";
		cout << "Created by <NAME>" << endl;
		drawCanvas();
		keyInput();
		gameWork();
		//basic game instructions listed below the game display
		cout << endl << endl << "Press Esc or quit to exit the game anytime" << endl;
		cout << "Press Tab to edit/change game settings" << endl;
		cout << "Control the snake using Left/Right/Up/Down keys" << endl;
	}
}

Snake::Snake () { //default constructor
	warpWalls = true; //warping default allowed
	gameWidth = 20;
	gameHeight = 20;
	tailLength = 0;
	snakeHead = 'O';
	snakeTail = 'o';
	initialGame();
	gamePlay();
}

Snake::Snake(int requiredWidth, int requiredHeight, bool warp) {
	warpWalls = warp;
	gameWidth = requiredWidth;
	gameHeight = requiredHeight;
	tailLength = 0;
	snakeHead = 'O';
	snakeTail = 'o';
	initialGame();
	gamePlay();
}

Snake::Snake(const int requiredWidth, const int requiredHeight, const char specifiedHead, const char specifiedTail, bool warp) {
	warpWalls = warp;
	gameWidth = requiredWidth;
	gameHeight = requiredHeight;
	tailLength = 0;
	snakeHead = specifiedHead;
	snakeTail = specifiedTail;
	initialGame();
	gamePlay();
}

Snake::~Snake () {
	//just some ending dialouge
	if (score < 100)
		cout << endl << "Can't you do better than that?" << endl;
	else if (score < 250)
		cout << endl << "That's a good score, think you can beat that?" << endl;
	else if (score < 500)
		cout << endl << "Very impressive score, tough to top" << endl;
	else 
		cout << endl << "Insane score, no one can beat that!" << endl;
}

void Snake::edit() {
	pickEdit: cout << endl << "What gameplay settings would you like to edit: " << endl;
	cout << "\t (1) Game Width \n\t (2) Game Height \n\t (3) Head Symbol \n\t (4) Tail Symbol \n\t (5) Boundary Warp";
	cout << endl;
	int selection;
	cin >> selection;
	switch (selection) { //switch table regarding what game setting user chose the edit
		case 1:
			cout << "Original height was: " << gameHeight;
			cout << endl << "Pick your new height: ";
			cin >> gameHeight;
			break;
		case 2: 
			cout << "Original width was: " << gameWidth;
			cout << endl << "Pick your new width: ";
			cin >> gameWidth;
			break;
		case 3: 
			cout << "Original head symbol was: " << snakeHead;
			cout << endl << "Pick your new snake head: ";
			cin >> snakeHead;
			break;
		case 4: 
			cout << "Original tail symbol was: " << snakeTail;
			cout << endl << "Pick your new snake tail: ";
			cin >> snakeTail;
			break;
		case 5: 
			warpWalls ^= 1; //flip boolean value
			cout << "Boundary Warp will now be: ";
			(warpWalls)? cout << "True" : cout << "False";
			cout << endl << "Confirm switch with Y/y, abort with N/n:  ";
			char boolSwitch;
			cin >> boolSwitch;
			if (boolSwitch == 'n' || boolSwitch == 'N')
				warpWalls ^= 1;
			break;
		default:
			cout << endl << "Wrong selection picked, try again: " << endl;
			goto pickEdit;
			break;
	}
}