I am making Yahtzee and this is what I have so far.

This is my ThingsThatNeverChange.h header

#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <string>
#include <algorithm>
#include <ctime>
#include <windows.h>
#include <conio.h>
#include <dos.h>
#include <math.h>
using namespace std;

char savenum = 'y';
char rollAgain = 'y';
int i;
const int Max_Rolls = 3;
int Rolls = 1;
int die[5]; // Array that generates randomnumbers from 1-6
int Hold[5]; // My holding array that lets the user input the number he wants to save.
int Rollsleft();
const int LOW = 1, HIGH = 6;
int Max_Turns = 13;
int Turns = 1;
int choice;
string name;

void gotoxy(int xpos, int ypos)
{
  COORD scrn;
  HANDLE hOuput = GetStdHandle(STD_OUTPUT_HANDLE);
  scrn.X = xpos; scrn.Y = ypos;
  SetConsoleCursorPosition(hOuput,scrn);
}
 
#define _WIN32_WINNT 0x0500

bool SetWindow(int Width, int Height);
bool SetWindow(int Width, int Height)
{
	_COORD coord;
	coord.X = Width;
	coord.Y = Height;

	_SMALL_RECT Rect;
	Rect.Top = 0;
	Rect.Left = 0;
	Rect.Bottom = Height - 1;
	Rect.Right = Width - 1;

	// Get handle of the standard output
	HANDLE Handle = GetStdHandle(STD_OUTPUT_HANDLE);
	if (Handle == NULL)
	{
		cout<<"Failure in getting the handle\n"<<GetLastError();
		return FALSE;
	}

	// Set screen buffer size to that specified in coord
	if(!SetConsoleScreenBufferSize(Handle, coord))
	{
		cout<<"Failure in setting buffer size\n"<<GetLastError();
		return FALSE;
	}

	// Set the window size to that specified in Rect
	if(!SetConsoleWindowInfo(Handle, TRUE, &Rect))
	{
		cout<<"Failure in setting window size\n"<<GetLastError();
		return FALSE;
	}

	return TRUE;
}

This is my Scorecard.h header

#include <iostream>
#include <string>

#pragma region Rolls Left

int Rollsleft()
{
	if (Rolls < Max_Rolls);
	{
		cout << "Rolls Remaining: " << Max_Rolls - Rolls << endl; 
	}
	if(Rolls == Max_Rolls)
		{
			cout << "End Turn." << endl;
		}
	return 0;
}
#pragma endregion

int Turnsleft()
{
	if (Turns < Max_Turns)
	{
		cout << "Turns left = " << Max_Turns - Turns << endl;
	}
	else if (Turns == Max_Turns)
	{
		cout << "Game Over" << endl;
	}
	return 0;
}

int TheDie()
{
	die[0] = rand() % (HIGH - LOW + 1) + LOW; 
    die[1] = rand() % (HIGH - LOW + 1) + LOW; 
    die[2] = rand() % (HIGH - LOW + 1) + LOW; 
    die[3] = rand() % (HIGH - LOW + 1) + LOW; 
    die[4] = rand() % (HIGH - LOW + 1) + LOW; 
	return 0;
}

void EndofTurn()
{
	cout << "==============================================================================================" << endl;
	cout << "=                                                                                            =" << endl;
	cout << "=                                    End of Turn                                             =" << endl;
	cout << "=                                                                                            =" << endl;
	cout << "==============================================================================================" << endl;
}
void Scorecard()
{
	
	
	cout << "==============================================================================================" << endl;
	cout << "==============================================================================================" << endl;
	cout << "=                                                                                            =" << endl;
    cout << "=                                  Yahtzee ScoreCard                                         =" << endl;
	cout << "=                                                                                            =" << endl;
	cout << "==============================================================================================" << endl;
	cout << endl;
	cout << "==============================================================================================" << endl;
	cout << endl;
	cout << "==============================================================================================" << endl;
	cout << "==============================================================================================" << endl;
	cout << "=                                                                                            =" << endl;
	cout << "=                                                                                            =" << endl;
	cout << "=   Aces        Twos        Threes        Fours        Fives        Sixes        Yahtzee     =" << endl;
	cout << "=                                                                                            =" << endl;
	cout << "=                                                                                            =" << endl;
	cout << "=   Doubles     Triples     Four of a Kind     Straight     Full House   Bonus    Chance     =" << endl;
	cout << "=                                                                                            =" << endl;
	cout << "=                                                                                            =" << endl;
	cout << "==============================================================================================" << endl;
	cout << "==============================================================================================" << endl;
	cout << Rollsleft() << "                                                                                            =" << endl;
	TheDie();
	cout << "= You rolled a: " << die[0] <<"                                                                            =" << endl;
	cout << "= You rolled a: " << die[1] <<"                                                                            =" << endl;
	cout << "= You rolled a: " << die[2] <<"                                                                            =" << endl;
	cout << "= You rolled a: " << die[3] <<"                                                                            =" << endl;
	cout << "= You rolled a: " << die[4] <<"                                                                            =" << endl;
	cout << "==============================================================================================" << endl;
	cout << "=                                                                                            =" << endl;
	cout << "==============================================================================================" << endl;
}

void prompts()
{
	gotoxy(42,8);
	cout << "Type your name: ";
	getline(cin,name);
	gotoxy(17,29);
	cout << "Do you want to re-roll? (y/n) ";
	cin >> rollAgain;
	if (rollAgain != 'y')
	{
		gotoxy(17,29);
		cout << "Do you want to save any numbers? (y/n) ";
		cin >> savenum;
		if (savenum != 'y')
		{
			gotoxy(0,28);
			EndofTurn();
		}
		else if (savenum == 'y')
		{
			gotoxy(17,29);
			cout << "What die do you want to save?";
			cin >> Hold[0];
		}
	}
}

This is my main.cpp

#include "ThingsThatNeverChange.h"
#include "Scorecard.h"

#pragma region Main 

int main()
{   
	srand(time(0));
	Scorecard();
	prompts();
	system("pause");
	return 0;
}
#pragma endregion

I need help in making a good hold function for storing my die. I need a code that lets me erase one line of code and replace it with something else. Kind of like system("cls"); but for one line. I also need a scoring function. I have a switch statement that lets me choose how many dice i wish to re roll and it outputs a random number from 1-6.

Here is that code.

int fifth_case_roll_5_Die() // Randomizes 5 numbers from 1 - 6
{
    die[0] = rand() % (HIGH - LOW + 1) + LOW; 
    die[1] = rand() % (HIGH - LOW + 1) + LOW; 
    die[2] = rand() % (HIGH - LOW + 1) + LOW; 
    die[3] = rand() % (HIGH - LOW + 1) + LOW; 
    die[4] = rand() % (HIGH - LOW + 1) + LOW; 
	cout << endl;
	cout << "_____________________________________________________________________" << endl;
	cout << "You rolled a: " << die[0] << endl;
	cout << "You rolled a: " << die[1] << endl;
	cout << "You rolled a: " << die[2] << endl;
	cout << "You rolled a: " << die[3] << endl;
	cout << "You rolled a: " << die[4] << endl;
	cout << endl;
	cout << "_____________________________________________________________________" << endl;
	cout << endl;
	return 0;
}
int fourth_case_roll_4_Die() // Randomizes 4 numbers from 1 - 6
{
    die[0] = rand() % (HIGH - LOW + 1) + LOW; 
    die[1] = rand() % (HIGH - LOW + 1) + LOW; 
    die[2] = rand() % (HIGH - LOW + 1) + LOW; 
    die[3] = rand() % (HIGH - LOW + 1) + LOW; 
	cout << endl;
	cout << "_____________________________________________________________________" << endl;
	cout << endl;
	cout << "You rolled a: " << die[0] << endl;
	cout << "You rolled a: " << die[1] << endl;
	cout << "You rolled a: " << die[2] << endl;
	cout << "You rolled a: " << die[3] << endl;
	cout << endl;
	cout << "_____________________________________________________________________" << endl;
	cout << endl;
	return 0;
}
int third_case_roll_3_Die() // Randomizes 3 numbers from 1 - 6
{
    die[0] = rand() % (HIGH - LOW + 1) + LOW; 
    die[1] = rand() % (HIGH - LOW + 1) + LOW; 
    die[2] = rand() % (HIGH - LOW + 1) + LOW; 
	cout << endl;
	cout << "_____________________________________________________________________" << endl;
	cout << endl;
	cout << "You rolled a: " << die[0] << endl;
	cout << "You rolled a: " << die[1] << endl;
	cout << "You rolled a: " << die[2] << endl;
	cout << endl;
	cout << "_____________________________________________________________________" << endl;
	cout << endl;
	return 0;
}
int second_case_roll_2_Die() // Randomizes 2 numbers from 1 - 6
{
    die[0] = rand() % (HIGH - LOW + 1) + LOW; 
    die[1] = rand() % (HIGH - LOW + 1) + LOW; 
	cout << endl;
	cout << "_____________________________________________________________________" << endl;
	cout << endl;
	cout << "You rolled a: " << die[0] << endl;
	cout << "You rolled a: " << die[1] << endl;
	cout << endl;
	cout << "_____________________________________________________________________" << endl;
	cout << endl;
 return 0;
}
int first_case_roll_1_Die() // Randomizes a random number from 1 - 6
{
	die[0] = rand() % (HIGH - LOW + 1) + LOW;
	cout << endl;
	cout << "_____________________________________________________________________" << endl;
	cout << "You rolled a: " << die[0] << endl;
	cout << endl;
	cout << "_____________________________________________________________________" << endl;
	cout << endl;
	return 0;
}

else if (rollAgain == 'y')
			{
			cout << "Do you want to save any numbers before you re roll? (y/n): ";
			cin >> savenum;
			if (savenum != 'y')
			 {
				cout << "How many die do you want to re roll? ";
				cin >> choice;
				switch (choice)
				 {
					case 1: 
						 first_case_roll_1_Die();
						 break;
					case 2: 
						 second_case_roll_2_Die();
						 break;
					case 3:
						 third_case_roll_3_Die();
						 break;
					case 4:
						 fourth_case_roll_4_Die();
						 break;
					case 5:
						 fifth_case_roll_5_Die();
						 break;
				 }
   }

I wanted to thank anyone out there that can help me out and also for sparing some of their time and helping out a student in programming. This really means a lot to me. I have always wanted to study programming. I have the determination to finish strong. I just need a little help. If anyone out there can help me, thank you. I will try and do the same for you next time. Promise.

Your friend, Zvjezdan.

I strongly suggest breaking down your problem into tiny pieces. People are much more willing to help you solve generally useful problems rather than your specific problem.

For example, if you start a thread asking "How do I erase a line from the terminal?" you will likely get some answers, whereas if you ask "Here is my 3000 line program, what am I doing wrong?" you will likely not get any answers.

ThingsThatNeverChange.h seems like a bad idea - it contains so many global variables! You should at least encapsulate these in a Settings class or something like that.

commented: good guidlines +0
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.