PA7

main.c

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Author:	Nathan Scott
//Class:	CptS 121, Fall  2015, Section 01, Lab Section 11.
//PA#:		7
//Due:		4DEC2015
//Type:		program entrance file.
//Purpose:	to performance logical arithmetic.
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//1. (5 pts) A user interface with options similar to the following :
	//a. Learn about how to use the program
	//b. Enter your initials(3 individual characters...)
	//c. Difficulty selection
	//d. Start a new sequence of problems
	//e. Save and Quit
//2. (25 pts - 5 pt / level) Generate mathematical problems based on the difficulty level selected.You must implement the following five levels of difficulty :
	//a. Level 1 - Easy : Includes addition and subtraction problems, with positive single digit operands and up to three terms only(i.e.d1 + d2 - d3 = )
	//b. Level 2 - Fair : Includes multiplication problems, with positive single digit operands and up to two terms only(i.e.d1 x d2 = )
	//c. Level 3 - Intermediate : Includes division problems, with positive single digit operands and up to two terms only(i.e.d1 / d2 = );
	//Note: results should be shown in the form Num R Remainder, i.e. if the problem is 5 / 3, then the answer should be provided as 1 R 2.
	//d. Level 4 - Hard : Includes a mix of addition, subtraction, multiplication, and division problems, with positive and negative single digit operands and up to three terms only(i.e.d1 + -d2 / d3 = ); Hint: you may have to first find a common denominator.
	//e. Level 5 - Impossible : Includes a mix of addition, subtraction, multiplication, and division problems, with positive and negative two and three digit operands and up to four terms only(i.e.dd1 + -ddd2 x ddd3 / dd4 = );
	//Hint: you may have to first find a common denominator.
//3. (5 pts) Allow the user to enter an answer corresponding to a generated math problem
//4. (10 pts) Evaluate the answer provided by the user.The user gets a certain number of points for correct answers and loses points for incorrect answers.The number of points should directly relate to the difficulty of the problem.
//5. (10 pts) Each level must generate a sequence of ten problems
//6. (10 pts) Within each level, problems should become a little more difficult as the user enters correct answers
//7. (10 pts) Once the user quits the program, output the user's initials and total score to a file
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#include "header.h"

int main(void){
	//declare variables.
	char input, userInit[] = { NULL };
	int inputReturn = 0, level = 0, userScore[] = { 0 , 0 };

	system("mode con cols=140 lines=50");//define window size.
	system("color 5f");//change window color.

	srand((unsigned)time(0));//generate seed for rand().
	do{//do while loop start.
		system("cls");//clean screen.
		printMenu();//Prints out the menu.
		inputReturn = scanf("%c", &input);
		input = tolower(input);//if user input is upper character, then convert to lower character.

		if (inputReturn != 1 || (input != 'a' && input != 'b' && input != 'c' && input != 'd' && input != 'e' && input != 'x')){//determine user enter is valid or not.
			system("cls");
			printf("\n***************************************\nError: please enter a valid choice!\n***************************************\n\n");
			system("pause");
			system("cls");
		}
		else
		{//if user input is valid then enter else clause.
			if (input == 'a'){//a. Learn about how to use the program.
				howToUse();
			}

			if (input == 'b'){//b. Enter your initials (3 individual characters...).
				initials(userInit);
			}

			if (input == 'c'){//c. Difficulty selection.
				if (userInit[0] == NULL || userInit[1] == NULL || userInit[2] == NULL){
					system("cls");
					printf("\n***************************************\nError: please enter your initials first!\n***************************************\n\n");
					system("pause");
					system("cls");
				}
				else{
					level = difficulty();
				}
			}

			if (input == 'd'){//d. Start a new sequence of problems.
				if (DEBUG == 1){//debug mode, it could be turn off in header file.
					printf("\nDifficulty = %d\n\n", level);
					system("pause");
				}

				if (level < 1 || level >5){
					system("cls");
					printf("\n***************************************\nError: please choose a level first!\n***************************************\n\n");
					system("pause");
					system("cls");
				}
				else{
					switch (level){
						case 1:{
							questionLevel1(userScore);
							break;
						}
						case 2:{
							questionLevel2(userScore);
							break;
						}
						case 3:{
							questionLevel3(userScore);
							break;
						}
						case 4:{
							questionLevel4(userScore);
							break;
						}
						case 5:{
							questionLevel5(userScore);
							break;
						}
					}
				}
			}

			if (input == 'e'){//e. Save and Quit.
				if (userScore[0] == 0){
					system("cls");
					printf("\n***************************************\nError: please do the math problems first!\n***************************************\n\n");
					system("pause");
					system("cls");
				}
				else{
					saveQuit(userInit, userScore);
				}
			}
		}
		fflush(stdin);//clear scanf buffer.
	} while (input != 'x');//end do while loop when input == x.
	saveQuit(userInit, userScore);
	system("cls");
	printf("\n\nGood Bye!\n\n");

	system("pause");
	return 0;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//THE END
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

header.h

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Author:	Nathan Scott
//Class:	CptS 121, Fall  2015, Section 01, Lab Section 11.
//PA#:		7
//Due:		4DEC2015
//Type:		header file.
//Purpose:	include lib and pre-define functions.
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#include <stdio.h>
#include <ctype.h>
#include <math.h>
#include <time.h>
#include <stdlib.h>
#include <string.h>
#ifndef _HEADERNAME_H
#define _HEADERNAME_H
#define _CRT_SECURE_NO_WARNINGS
#define DEBUG 1 //switch on(1)/off(0) debug mode.

void printMenu(void);
void howToUse(void);
void initials(char userInit[3]);
int difficulty(void);
void questionLevel1(int userScore[2]);
void questionLevel2(int userScore[2]);
void questionLevel3(int userScore[2]);
void questionLevel4(int userScore[2]);
void questionLevel5(int userScore[2]);
void saveQuit(char userInit[3], int userScore[2]);

#endif
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//THE END
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

func.c

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Author:	Nathan Scott
//Class:	CptS 121, Fall  2015, Section 01, Lab Section 11.
//PA#:		7
//Due:		4DEC2015
//Type:		source file.
//Purpose:	define functions and logics.
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#include "header.h"

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//1. (5 pts) A user interface with options similar to the following :
	//a. Learn about how to use the program
	//b. Enter your initials(3 individual characters...)
	//c. Difficulty selection
	//d. Start a new sequence of problems
	//e. Save and Quit
//2. (25 pts - 5 pt / level) Generate mathematical problems based on the difficulty level selected.You must implement the following five levels of difficulty :
	//a. Level 1 - Easy : Includes addition and subtraction problems, with positive single digit operands and up to three terms only(i.e.d1 + d2 - d3 = )
	//b. Level 2 - Fair : Includes multiplication problems, with positive single digit operands and up to two terms only(i.e.d1 x d2 = )
	//c. Level 3 - Intermediate : Includes division problems, with positive single digit operands and up to two terms only(i.e.d1 / d2 = );
	//Note: results should be shown in the form Num R Remainder, i.e. if the problem is 5 / 3, then the answer should be provided as 1 R 2.
	//d. Level 4 - Hard : Includes a mix of addition, subtraction, multiplication, and division problems, with positive and negative single digit operands and up to three terms only(i.e.d1 + -d2 / d3 = ); Hint: you may have to first find a common denominator.
	//e. Level 5 - Impossible : Includes a mix of addition, subtraction, multiplication, and division problems, with positive and negative two and three digit operands and up to four terms only(i.e.dd1 + -ddd2 x ddd3 / dd4 = );
	//Hint: you may have to first find a common denominator.
//3. (5 pts) Allow the user to enter an answer corresponding to a generated math problem
//4. (10 pts) Evaluate the answer provided by the user.The user gets a certain number of points for correct answers and loses points for incorrect answers.The number of points should directly relate to the difficulty of the problem.
//5. (10 pts) Each level must generate a sequence of ten problems
//6. (10 pts) Within each level, problems should become a little more difficult as the user enters correct answers
//7. (10 pts) Once the user quits the program, output the user's initials and total score to a file
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//printMenu() a user interface with options.
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void printMenu(void){
printf("\n\n\
The Arithmetic of the Whole Numbers Computer Based Training (AWNCBT)\n\n\
Author: Nathan Scott\n\
Version: 7.18\n\n\
--------------------------------------------MENU--------------------------------------------\n\
a. Learn about how to use the program\n\
b. Enter your initials (3 individual characters)\n\
c. Difficulty selection\n\
d. Start a new sequence of problems\n\
e. Save and Quit\n\
x. Exit\n\
--------------------------------------------------------------------------------------------\n\n\
Enter: ");
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//howToUse() Learn about how to use the program.
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void howToUse(void){
system("cls");
printf("Function: howToUse()\n\
Debug: %d\n\
\nHow to Use\n\
\n\
a.Level 1 - Easy : Includes addition and subtraction problems, with positive single digit operands and up to three terms only(i.e.d1 + d2 - d3 = )\n\n\
b.Level 2 - Fair : Includes multiplication problems, with positive single digit operands and up to two terms only(i.e.d1 x d2 = )\n\n\
c.Level 3 - Intermediate : Includes division problems, with positive single digit operands and up to two terms only(i.e.d1 / d2 = );\n\
Note: results should be shown in the form Num R Remainder, i.e. if the problem is 5 / 3, then the answer should be provided as 1 R 2.\n\n\
d.Level 4 - Hard : Includes a mix of addition, subtraction, multiplication, and division problems, with positive and negative single digit operands and up to three terms only(i.e.d1 + -d2 / d3 = ); Hint: you may have to first find a common denominator.\n\n\
e.Level 5 - Impossible : Includes a mix of addition, subtraction, multiplication, and division problems, with positive and negative	two and three digit operands and up to four terms only(i.e.dd1 + -ddd2 x ddd3 / dd4 = );\n\
\n\
See the difficulty table provided below :\n\
\n\
+-------------------------------------------------------------------------------------------------------+\n\
| LEVEL						| DIFFICULTY							|\n\
|-------------------------------------------------------------------------------------------------------|\n\
| Level 1					| Easy								|\n\
|-------------------------------------------------------------------------------------------------------|\n\
| Level 2					| Fair								|\n\
|-------------------------------------------------------------------------------------------------------|\n\
| Level 3					| Intermediate							|\n\
|-------------------------------------------------------------------------------------------------------|\n\
| Level 4					| Hard								|\n\
|-------------------------------------------------------------------------------------------------------|\n\
| Level 5					| Impossible							|\n\
+-------------------------------------------------------------------------------------------------------+\n\
\n",DEBUG);
	system("pause");
	system("cls");
}


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//initials() let the user enter their initials (3 individual characters...).
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void initials(char userInit[3]){
	int exitCond = 0;
	do{
		system("cls");
		printf("Function: initials()\n");
		printf("Debug: %d\n\n", DEBUG);

		printf("Please enter 3 individual characters of your initial (no comma or space need):\n\nEnter: ");
		if (scanf(" %c %c %c", &userInit[0], &userInit[1], &userInit[2]) != 3){//determine user enter is valid or not.
			system("cls");
			printf("\n***************************************\nError: please enter a valid choice!\n***************************************\n\n");
			system("pause");
			system("cls");
		}
		else if (DEBUG == 1){//debug mode, it could be turn off in header file.
			userInit[0] = tolower(userInit[0]);
			userInit[1] = tolower(userInit[1]);
			userInit[2] = tolower(userInit[2]);
			printf("\nuserInit[0] = %c\nuserInit[1] = %c\nuserInit[2] = %c\n\n", userInit[0], userInit[1], userInit[2]);
			exitCond = 1;
			system("pause");
		}

		fflush(stdin);//clear scanf buffer.
	} while (exitCond = 0);
}


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//difficulty() generate mathematical problems based on the difficulty level selected.You must implement the five levels of difficulty.
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int difficulty(void){
	int level = 0;
	do{
		system("cls");
		printf("Function: difficulty()\n");
		printf("Debug: %d\n\n", DEBUG);

		printf("Please enter mathematical problems difficulty level (1 ~ 5):\n\nEnter: ");
		if (scanf("%d", &level) != 1 || level < 0 || level > 5){//determine user enter is valid or not.
			system("cls");
			printf("\n***************************************\nError: please enter a valid choice!\n***************************************\n\n");
			system("pause");
			system("cls");
		}
		else{
			printf("\nDifficulty: %d\n\n", level);
			system("pause");
			return level;
		}
		fflush(stdin);//clear scanf buffer.
	} while (level<1 || level>5);
}


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//questionLevel1() Easy : Includes addition and subtraction problems, with positive single digit operands and up to three terms only(i.e.d1 + d2 - d3 = ).
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void questionLevel1(int userScore[2]){
	int counter = 0, size = 0, num1 = 0, num2 = 0, num3 = 0, input = NULL, correctAnswer = NULL, index = NULL;
	char operators[] = { '+', '-' }, op[] = { '\0' }, op1 = '\0', op2 = '\0';
	userScore[0] = 1;//setup question level at 1;
	size = sizeof(operators) / sizeof(operators[0]);

	while (counter < 10) {
		system("cls");
		printf("Function: questionLevel1()\n");
		printf("Debug: %d\n\n", DEBUG);

		num1 = rand() % 9 + 1;//generate num1 randomly.
		num2 = rand() % 9 + 1;//generate num2 randomly.
		num3 = rand() % 9 + 1;//generate num3 randomly.

		for (int i = 0; i < size; i++){//generate operators randomly.
			index = rand() % size;
			op[i] = operators[index];//total 4 different combinations.
			if (DEBUG == 1){//debug mode, it could be turn off in header file.
				printf("Operator = '%c'\n", op[i]);
			}
		}

		op1 = op[rand() % size];//assign operator to op1 randomly;
		op2 = op[rand() % size];//assign operator to op2 randomly;

		if (DEBUG == 1){//debug mode, it could be turn off in header file.
			printf("\nop1 = '%c', op2 = '%c'\n", op1,op2);
		}

		//total 4 different combinations.
		if (op1 == '+' && op2 == '+'){
			correctAnswer = num1 + num2 + num3;
		}
		if (op1 == '+' && op2 == '-'){
			correctAnswer = num1 + num2 - num3;
		}
		if (op1 == '-' && op2 == '+'){
			correctAnswer = num1 - num2 + num3;
		}
		if (op1 == '-' && op2 == '-'){
			correctAnswer = num1 - num2 - num3;
		}

		if (DEBUG == 1){//debug mode, it could be turn off in header file.
			printf("\ncorrectAnswer = %d\n", correctAnswer);
		}
		
		printf("\nLv.1 #%d: %d %c %d %c %d = ?\n\nEnter: ", counter + 1, num1, op1, num2, op2, num3);
		if (scanf("%d", &input) != 1){//determine user enter is valid or not.
			system("cls");
			printf("\n***************************************\nError: please enter a valid choice!\n***************************************\n\n");
			system("pause");
			system("cls");
		}
		else{
			if (input == correctAnswer){
				userScore[1] += 1;//[1] indicates total user score.
				printf("\n\nCorrected!\nYour answer is: %d and your current score is: %d\n\n", input, userScore[1]);
			}
			else{
				userScore[1] += 0;//[1] indicates total user score.
				printf("\n\nWrong!\nYour answer is: %d and your current score is: %d\n\n", input, userScore[1]);
			}
		}

		fflush(stdin);//clear scanf buffer.
		counter++;
		system("pause");
		system("cls");
	}
}


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//questionLevel2() Fair : Includes multiplication problems, with positive single digit operands and up to two terms only(i.e.d1 x d2 = ).
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void questionLevel2(int userScore[2]){
	int counter = 0, size = 0, num1 = 0, num2 = 0, input = NULL, correctAnswer = NULL, index = NULL;
	char operators[] = { 'x' }, op[] = { '\0' }, op1 = '\0';
	userScore[0] = 2;//setup question level at 2;
	size = sizeof(operators) / sizeof(operators[0]);

	while (counter < 10) {
		system("cls");
		printf("Function: questionLevel2()\n");
		printf("Debug: %d\n\n", DEBUG);

		num1 = rand() % 9 + 1;//generate num1 randomly.
		num2 = rand() % 9 + 1;//generate num2 randomly.

		for (int i = 0; i < size; i++){//generate operators randomly.
			index = rand() % size;
			op[i] = operators[index];//total 1 different combinations.
			if (DEBUG == 1){//debug mode, it could be turn off in header file.
				printf("Operator = '%c'\n", op[i]);
			}
		}

		op1 = op[rand() % size];//assign operator to op1 randomly;

		if (DEBUG == 1){//debug mode, it could be turn off in header file.
			printf("\nop1 = '%c'\n", op1);
		}

		//total 1 combinations.
		if (op1 == 'x'){
			correctAnswer = num1 * num2;
		}

		if (DEBUG == 1){//debug mode, it could be turn off in header file.
			printf("\ncorrectAnswer = %d\n", correctAnswer);
		}

		printf("\nLv.2 #%d: %d %c %d = ?\n\nEnter: ", counter + 1, num1, op1, num2);
		if (scanf("%d", &input) != 1){//determine user enter is valid or not.
			system("cls");
			printf("\n***************************************\nError: please enter a valid choice!\n***************************************\n\n");
			system("pause");
			system("cls");
		}
		else{
			if (input == correctAnswer){
				userScore[1] += 1;//[1] indicates total user score.
				printf("\n\nCorrected!\nYour answer is: %d and your current score is: %d\n\n", input, userScore[1]);
			}
			else{
				userScore[1] += 0;//[1] indicates total user score.
				printf("\n\nWrong!\nYour answer is: %d and your current score is: %d\n\n", input, userScore[1]);
			}
		}

		fflush(stdin);//clear scanf buffer.
		counter++;
		system("pause");
		system("cls");
	}
}


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//questionLevel3() Intermediate : Includes division problems, with positive single digit operands and up to two terms only(i.e.d1 / d2 = ).
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void questionLevel3(int userScore[2]){
	int counter = 0, size = 0, index = NULL;
	float input = 0.0, num1 = 0.0, num2 = 0.0, correctAnswer = 0.0;
	char operators[] = { '/' }, op[] = { '\0' }, op1 = '\0';
	userScore[0] = 3;//setup question level at 3;
	size = sizeof(operators) / sizeof(operators[0]);

	while (counter < 10) {
		system("cls");
		printf("Function: questionLevel3()\n");
		printf("Debug: %d\n\n", DEBUG);

		do{
			num1 = (rand() % 21 - 10) / 1.00;//generate num1 randomly.
			num2 = (rand() % 21 - 10) / 1.00;//generate num2 randomly.
		} while (num1 < num2);

		if (DEBUG == 1){//debug mode, it could be turn off in header file.
			printf("num1 = %.2lf\nnum2 = %.2lf\n\n", num1, num2);
		}
		
		for (int i = 0; i < size; i++){//generate operators randomly.
			index = rand() % size;
			op[i] = operators[index];//total 1 different combinations.
			if (DEBUG == 1){//debug mode, it could be turn off in header file.
				printf("Operator = '%c'\n", op[i]);
			}
		}

		op1 = op[rand() % size];//assign operator to op1 randomly;

		if (DEBUG == 1){//debug mode, it could be turn off in header file.
			printf("\nop1 = '%c'\n", op1);
		}

		//total 1 combinations.
		if (op1 == '/'){
			correctAnswer = num1 / num2;
			correctAnswer = (int)((correctAnswer * 100) + 0.5) / 100.00;//reserves two decimals.
		}

		if (DEBUG == 1){//debug mode, it could be turn off in header file.
			printf("\ncorrectAnswer = %.2lf\n", correctAnswer);
		}

		printf("\nLv.3 #%d: %.2lf %c %.2lf = ?\n\nEnter: ", counter + 1, num1, op1, num2);
		if (scanf("%f", &input) != 1){//determine user enter is valid or not.
			system("cls");
			printf("\n***************************************\nError: please enter a valid choice!\n***************************************\n\n");
			system("pause");
			system("cls");
		}
		else{
			if (input == correctAnswer){
				userScore[1] += 1;//[1] indicates total user score.
				printf("\n\nCorrected!\nYour answer is: %.2lf and your current score is: %d\n\n", input, userScore[1]);
				system("pause");
				system("cls");
			}
			else{
				userScore[1] += 0;//[1] indicates total user score.
				printf("\n\nWrong!\nYour answer is: %.2lf and your current score is: %d\n\n", input, userScore[1]);
				system("pause");
				system("cls");
			}
		}

		fflush(stdin);//clear scanf buffer.
		counter++;
	}
}


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//questionLevel4() Hard : Includes a mix of addition, subtraction, multiplication, and division problems, with positive and negative single digit operands and up to three terms only(i.e.d1 + -d2 / d3 = ); Hint: you may have to first find a common denominator.
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void questionLevel4(int userScore[2]){
	int counter = 0, size = 0, index = NULL;
	float input = 0.0, num1 = 0.0, num2 = 0.0, num3 = 0.0, correctAnswer = 0.0;
	char operators[] = { '+', '-', 'x', '/' }, op[] = { '\0' }, op1 = '\0', op2 = '\0';
	userScore[0] = 3;//setup question level at 3;
	size = sizeof(operators) / sizeof(operators[0]);

	while (counter < 10) {
		system("cls");
		printf("Function: questionLevel4()\n");
		printf("Debug: %d\n\n", DEBUG);

		while (num1 == 0 || num2 == 0 || num3 == 0){
			num1 = (rand() % 21 - 10) / 1.00;//generate num1 randomly.
			num2 = (rand() % 21 - 10) / 1.00;//generate num2 randomly.
			num3 = (rand() % 21 - 10) / 1.00;//generate num3 randomly.
		}

		if (DEBUG == 1){//debug mode, it could be turn off in header file.
			printf("num1 = %.2lf\nnum2 = %.2lf\nnum3 = %.2lf\n\n", num1, num2, num3);
		}

		for (int i = 0; i < size; i++){//generate operators randomly.
			index = rand() % size;
			op[i] = operators[index];//total 1 different combinations.
			if (DEBUG == 1){//debug mode, it could be turn off in header file.
				printf("Operator = '%c'\n", op[i]);
			}
		}

		op1 = op[rand() % size];//assign operator to op1 randomly;
		op2 = op[rand() % size];//assign operator to op2 randomly;

		if (DEBUG == 1){//debug mode, it could be turn off in header file.
			printf("\nop1 = '%c'\nop2 = '%c'\n", op1, op2);
		}

		//4 groups and 4 combinations in each group.
		//total 4 combinations.
		if (op1 == '+' && op2 == '+'){correctAnswer = num1 + num2 + num3;}
		if (op1 == '+' && op2 == '-'){correctAnswer = num1 + num2 - num3;}
		if (op1 == '-' && op2 == '+'){correctAnswer = num1 - num2 + num3;}
		if (op1 == '-' && op2 == '-'){correctAnswer = num1 - num2 - num3;}

		//total 4 combinations.
		if (op1 == 'x' && op2 == 'x'){correctAnswer = num1 * num2 * num3;}
		if (op1 == 'x' && op2 == '/'){correctAnswer = num1 * num2 / num3;}
		if (op1 == '/' && op2 == 'x'){correctAnswer = num1 / num2 * num3;}
		if (op1 == '/' && op2 == '/'){correctAnswer = num1 / num2 / num3;}

		//total 4 combinations.
		if (op1 == '+' && op2 == 'x'){correctAnswer = num1 + num2 * num3;}
		if (op1 == 'x' && op2 == '+'){correctAnswer = num1 * num2 + num3;}
		if (op1 == '+' && op2 == '/'){correctAnswer = num1 + num2 / num3;}
		if (op1 == '/' && op2 == '+'){correctAnswer = num1 / num2 + num3;}

		//total 4 combinations.
		if (op1 == '-' && op2 == 'x'){correctAnswer = num1 - num2 * num3;}
		if (op1 == 'x' && op2 == '-'){correctAnswer = num1 * num2 - num3;}
		if (op1 == '-' && op2 == '/'){correctAnswer = num1 - num2 / num3;}
		if (op1 == '/' && op2 == '-'){correctAnswer = num1 / num2 - num3;}

		correctAnswer = (int)((correctAnswer * 100) + 0.5) / 100.00;//reserves two decimals.

		if (DEBUG == 1){//debug mode, it could be turn off in header file.
			printf("\ncorrectAnswer = %.2lf\n", correctAnswer);
		}

		printf("\nLv.4 #%d: %.2lf %c %.2lf %c %.2lf = ?\n\nEnter: ", counter + 1, num1, op1, num2, op2, num3);
		if (scanf("%f", &input) != 1){//determine user enter is valid or not.
			system("cls");
			printf("\n***************************************\nError: please enter a valid choice!\n***************************************\n\n");
			system("pause");
			system("cls");
		}
		else{
			if (input == correctAnswer){
				userScore[1] += 1;//[1] indicates total user score.
				printf("\n\nCorrected!\nYour answer is: %.2lf and your current score is: %d\n\n", input, userScore[1]);
				system("pause");
				system("cls");
			}
			else{
				userScore[1] += 0;//[1] indicates total user score.
				printf("\n\nWrong!\nYour answer is: %.2lf and your current score is: %d\n\n", input, userScore[1]);
				system("pause");
				system("cls");
			}
		}

		fflush(stdin);//clear scanf buffer.
		counter++;
	}
}


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//questionLevel5() Hard : Includes a mix of addition, subtraction, multiplication, and division problems, with positive and negative single digit operands and up to three terms only(i.e.d1 + -d2 / d3 = ); Hint: you may have to first find a common denominator.
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void questionLevel5(int userScore[2]){
	int counter = 0, size = 0, index = NULL;
	float input = 0.0, num1 = 0.0, num2 = 0.0, num3 = 0.0, num4 = 0.0, correctAnswer = 0.0;
	char operators[] = { '+', '-', 'x', '/' }, op[] = { '\0' }, op1 = '\0', op2 = '\0', op3 = '\0';
	userScore[0] = 3;//setup question level at 3;
	size = sizeof(operators) / sizeof(operators[0]);

	while (counter < 10) {
		system("cls");
		printf("Function: questionLevel5()\n");
		printf("Debug: %d\n\n", DEBUG);

		while (num1 == 0 || num2 == 0 || num3 == 0 || num4 == 0){
			num1 = (rand() % 21 - 10) / 1.00;//generate num1 randomly.
			num2 = (rand() % 21 - 10) / 1.00;//generate num2 randomly.
			num3 = (rand() % 21 - 10) / 1.00;//generate num3 randomly.
			num4 = (rand() % 21 - 10) / 1.00;//generate num3 randomly.
		}

		if (DEBUG == 1){//debug mode, it could be turn off in header file.
			printf("num1 = %.3lf\nnum2 = %.3lf\nnum3 = %.3lf\nnum4 = %.3lf\n\n", num1, num2, num3, num4);
		}

		for (int i = 0; i < size; i++){//generate operators randomly.
			index = rand() % size;
			op[i] = operators[index];//total 1 different combinations.
			if (DEBUG == 1){//debug mode, it could be turn off in header file.
				printf("Operator = '%c'\n", op[i]);
			}
		}

		op1 = op[rand() % size];//assign operator to op1 randomly;
		op2 = op[rand() % size];//assign operator to op2 randomly;
		op3 = op[rand() % size];//assign operator to op3 randomly;

		if (DEBUG == 1){//debug mode, it could be turn off in header file.
			printf("\nop1 = '%c'\nop2 = '%c'\nop3 = '%c'\n", op1, op2, op3);
		}

		//5 groups and 8 combinations in each group.
		//total 8 combinations.
		if (op1 == '+' && op2 == '+' && op2 == '+'){ correctAnswer = num1 + num2 + num3 + num4;}
		if (op1 == '+' && op2 == '+' && op2 == '-'){ correctAnswer = num1 + num2 + num3 - num4; }
		if (op1 == '+' && op2 == '-' && op2 == '+'){ correctAnswer = num1 + num2 - num3 + num4; }
		if (op1 == '-' && op2 == '+' && op2 == '+'){ correctAnswer = num1 - num2 + num3 + num4; }
		if (op1 == '-' && op2 == '-' && op2 == '-'){ correctAnswer = num1 - num2 - num3 - num4; }
		if (op1 == '-' && op2 == '-' && op2 == '+'){ correctAnswer = num1 - num2 - num3 + num4; }
		if (op1 == '-' && op2 == '+' && op2 == '-'){ correctAnswer = num1 - num2 + num3 - num4; }
		if (op1 == '+' && op2 == '-' && op2 == '-'){ correctAnswer = num1 + num2 - num3 - num4; }

		//total 8 combinations.
		if (op1 == 'x' && op2 == 'x' && op2 == 'x'){ correctAnswer = num1 * num2 * num3 * num4; }
		if (op1 == 'x' && op2 == 'x' && op2 == '/'){ correctAnswer = num1 * num2 * num3 / num4; }
		if (op1 == 'x' && op2 == '/' && op2 == 'x'){ correctAnswer = num1 * num2 / num3 * num4; }
		if (op1 == '/' && op2 == 'x' && op2 == 'x'){ correctAnswer = num1 / num2 * num3 * num4; }
		if (op1 == '/' && op2 == '/' && op2 == '/'){ correctAnswer = num1 / num2 / num3 / num4; }
		if (op1 == '/' && op2 == '/' && op2 == 'x'){ correctAnswer = num1 / num2 / num3 * num4; }
		if (op1 == '/' && op2 == 'x' && op2 == '/'){ correctAnswer = num1 / num2 * num3 / num4; }
		if (op1 == 'x' && op2 == '/' && op2 == '/'){ correctAnswer = num1 * num2 / num3 / num4; }

		//total 8 combinations.
		if (op1 == '+' && op2 == 'x' && op2 == 'x'){ correctAnswer = num1 + num2 * num3 * num4; }
		if (op1 == '+' && op2 == 'x' && op2 == '/'){ correctAnswer = num1 + num2 * num3 / num4; }
		if (op1 == '+' && op2 == '/' && op2 == 'x'){ correctAnswer = num1 + num2 / num3 * num4; }
		if (op1 == '+' && op2 == '/' && op2 == '/'){ correctAnswer = num1 + num2 / num3 / num4; }
		if (op1 == '-' && op2 == '/' && op2 == '/'){ correctAnswer = num1 - num2 / num3 / num4; }
		if (op1 == '-' && op2 == '/' && op2 == 'x'){ correctAnswer = num1 - num2 / num3 * num4; }
		if (op1 == '-' && op2 == 'x' && op2 == '/'){ correctAnswer = num1 - num2 * num3 / num4; }
		if (op1 == '-' && op2 == 'x' && op2 == 'x'){ correctAnswer = num1 - num2 * num3 * num4; }

		//total 8 combinations.
		if (op1 == 'x' && op2 == '+' && op2 == 'x'){ correctAnswer = num1 * num2 + num3 * num4; }
		if (op1 == 'x' && op2 == '+' && op2 == '/'){ correctAnswer = num1 * num2 + num3 / num4; }
		if (op1 == '/' && op2 == '+' && op2 == 'x'){ correctAnswer = num1 / num2 + num3 * num4; }
		if (op1 == '/' && op2 == '+' && op2 == '/'){ correctAnswer = num1 / num2 + num3 / num4; }
		if (op1 == '/' && op2 == '-' && op2 == '/'){ correctAnswer = num1 / num2 - num3 / num4; }
		if (op1 == '/' && op2 == '-' && op2 == 'x'){ correctAnswer = num1 / num2 - num3 * num4; }
		if (op1 == 'x' && op2 == '-' && op2 == '/'){ correctAnswer = num1 * num2 - num3 / num4; }
		if (op1 == 'x' && op2 == '-' && op2 == 'x'){ correctAnswer = num1 * num2 - num3 * num4; }

		//total 8 combinations.
		if (op1 == 'x' && op2 == 'x' && op2 == '+'){ correctAnswer = num1 * num2 * num3 + num4; }
		if (op1 == 'x' && op2 == '/' && op2 == '+'){ correctAnswer = num1 * num2 / num3 + num4; }
		if (op1 == '/' && op2 == 'x' && op2 == '+'){ correctAnswer = num1 / num2 * num3 + num4; }
		if (op1 == '/' && op2 == '/' && op2 == '+'){ correctAnswer = num1 / num2 / num3 + num4; }
		if (op1 == '/' && op2 == '/' && op2 == '-'){ correctAnswer = num1 / num2 / num3 - num4; }
		if (op1 == '/' && op2 == 'x' && op2 == '-'){ correctAnswer = num1 / num2 * num3 - num4; }
		if (op1 == 'x' && op2 == '/' && op2 == '-'){ correctAnswer = num1 * num2 / num3 - num4; }
		if (op1 == 'x' && op2 == 'x' && op2 == '-'){ correctAnswer = num1 * num2 * num3 - num4; }

		correctAnswer = (int)((correctAnswer * 1000) + 0.5) / 1000.00;//reserves two decimals.

		if (DEBUG == 1){//debug mode, it could be turn off in header file.
			printf("\ncorrectAnswer = %.3lf\n", correctAnswer);
		}

		printf("\nLv.5 #%d: %.3lf %c %.3lf %c %.3lf %c %.3lf = ?\n\nEnter: ", counter + 1, num1, op1, num2, op2, num3, op3, num4);
		if (scanf("%f", &input) != 1){//determine user enter is valid or not.
			system("cls");
			printf("\n***************************************\nError: please enter a valid choice!\n***************************************\n\n");
			system("pause");
			system("cls");
		}
		else{
			if (input == correctAnswer){
				userScore[1] += 1;//[1] indicates total user score.
				printf("\n\nCorrected!\nYour answer is: %.3lf and your current score is: %d\n\n", input, userScore[1]);
				system("pause");
				system("cls");
			}
			else{
				userScore[1] += 0;//[1] indicates total user score.
				printf("\n\nWrong!\nYour answer is: %.3lf and your current score is: %d\n\n", input, userScore[1]);
				system("pause");
				system("cls");
			}
		}

		fflush(stdin);//clear scanf buffer.
		counter++;
	}
}


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//saveQuit() Save and Quit
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void saveQuit(char userInit[3], int userScore[2]){
	if (DEBUG == 1){//debug mode, it could be turn off in header file.
		system("cls");
		printf("\nFunction: saveQuit()\n");
		printf("Debug = %d\n", DEBUG);
	}

	FILE *fPtr, *fPtrOut = NULL; //NULL ptr
	fPtr = fopen("result.log", "a+");
	if (fPtr == NULL){//relative path for filename, and determine file can be open or not.
		printf("\nError: the log file cannot be open!\n\n");
	}
	else{
		fprintf(fPtr, "\n\n*** User Stats ***\n\n");
		fprintf(fPtr, "Initials: %c%c%c\n", userInit[0], userInit[1], userInit[2]);
		fprintf(fPtr, "Level: %d\n", userScore[0]);
		fprintf(fPtr, "Score: %d\n", userScore[1]);
		fprintf(fPtr, "\n\n");
	}

	printf("\n\n%d files were saved and closed!\n\n", fcloseall());//output how many open files has been closed.
	system("pause");
}


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//nonRepeatRand().
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int nonRepeatRand(int num, int array[]){
	int x, p;
	int count;
	int i = 0;

	srand(time(NULL));

	for (count = 0; count < num; count++){
		array[count] = rand() % num + 1;
	}

	while (i < num){
		int r = rand() % num + 1;

		for (x = 0; x < i; x++)
		{
			if (array[x] == r){
				break;
			}
		}
		if (x == i){
			array[i++] = r;
		}
	}
	for (p = 0; p < num; p++){
		printf("%d ", array[p]);
	}
	return array;
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//THE END
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Five Card Draw Helping Code

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <String.h>

int main() {
	srand((unsigned)time(NULL));

	do {
		int arr[13] = {0}, pair = 0, threeKind = 0, fourKind = 0, straight = 0, counter = 0, list[5] = {0};


		printf("Step1. Generated 5 out of 13 faces\n\n");
		for (int i = 0; i < 5; i++) {
			arr[rand() % 13 - 1] += 1;
		}

		for (int i = 0; i < 13; i++) {
			printf("[%d]: %d \n", i + 1, arr[i]);
		}

		printf("\nStep2. Filter out empty faces and convert index as value\n\n");

		for (int i = 0; i < 13; i++) {
			if (arr[i] != NULL) {
				printf("[%d]: %d\t",i + 1,arr[i]);
				if(arr[i] > 1) {
					for (int j = 0; j < arr[i]; j++) {
						list[counter] = i + 1;
						printf("(%d): %d \n",counter,list[counter]);
						counter++;
					}
				} else {
					list[counter] = i + 1;
					printf("(%d): %d \n",counter,list[counter]);
					counter++;
				}

			}
		}
		
//		for(int i= 0; i<5; i++) {
//			list[i] = i + 1;
//			printf("[%d]: %d \n",i,list[i]);
//		}
		
		printf("\nStep3. Differentiate faces\n\n");

		for (int i = 0; i < 13; i++) {
			if (arr[i]!= NULL && arr[i] % 2 == 0) {
				printf("[%d]: %d \n",i + 1,arr[i]);
				pair += 1;
			}
			if (arr[i]!= NULL && arr[i] % 3 == 0) {
				printf("[%d]: %d \n",i + 1,arr[i]);
				threeKind += 1;
			}
			if (arr[i]!= NULL && arr[i] % 4 == 0) {
				printf("[%d]: %d \n",i + 1,arr[i]);
				fourKind += 1;
			}
		}
		
		counter = 0;
		for (int i = -1; i < 5; i++) {
			if (list[i] + 1 == list[i + 1]) {
				//printf("[%d]: %d \n",i + 1,list[i + 1]);
				counter++;
			}
			if (counter == 5)
			{
				straight = 1;
			}
		}

		printf("\nPair: %d  Three of Kind: %d  Four of Kind: %d  Straight: %d\n",pair,threeKind,fourKind,straight);
		system("pause");
	} while(true);

	return 0;
}