Well, i started my C++ book again after a year to learn more about the hardware of a computer, binary and others so i would understand more about my code and so i understand what i am doing.
So here is my code and i will explain the bug at the bottom.
Code:
#include <iostream>
#include <cstdlib>
#include <time.h>
using namespace std;
typedef unsigned short int USHORT;
const USHORT tokensThree = 3;
const USHORT tokensTwo = 2;
USHORT tokens = 12;
const char playY = 'y';
char inputYes;
const USHORT highRandom = 6;
USHORT randomNumber;
USHORT randomNumberTwo;
USHORT randomNumberThree;
int winThreeTokens(int firstNumber, int secondNumber, int thirdNumber)
{
if(firstNumber==secondNumber==thirdNumber)
{
cout << "Congratulations! You WON 3 Tokens!" << endl;
tokens = tokens + tokensThree;
cout << "You know have " << tokens << "tokens.";
}
return(firstNumber, secondNumber, thirdNumber);
}
int winTwoTokens(int firstNumber, int secondNumber, int thirdNumber)
{
if(firstNumber==secondNumber || firstNumber==thirdNumber || secondNumber==thirdNumber)
{
cout << endl << "Congratulations! You WON 2 Tokens!" << endl;
tokens = tokens + tokensTwo;
cout << "You know have " << tokens << "tokens.";
}
return(firstNumber, secondNumber, thirdNumber);
}
int Lose(int firstNumber, int secondNumber, int thirdNumber)
{
if(firstNumber!=secondNumber!=thirdNumber)
{
cout << endl << "HAHAHA Sorry, You lost THREE Tokens!";
tokens = tokens - 3;
if(tokens==0)
{
cout << endl << "You have " << tokens << "tokens.";
cout << endl << "Game Over!";
cout << endl << "Now Exiting...";
exit(0);
}
cout << endl << "You know have " << tokens << "tokens.";
}
return(firstNumber, secondNumber, thirdNumber);
}
void lever()
{
time_t clockTimeSeconds;
time(&clockTimeSeconds);
srand((unsigned int) clockTimeSeconds);
randomNumber = rand() % highRandom + 1;
randomNumberTwo = rand() % highRandom + 1;
randomNumberThree = rand() % highRandom + 1;
cout << endl << "Do you want to pull the BIG Lever right beside you?" << endl;
cout << "If so, Please type 'y' and press Return." << endl;
cin >> inputYes;
if(inputYes==playY)
{
cout << "Your numbers are:\t" << randomNumber << "\t" << randomNumberTwo << "\t" << randomNumberThree;
winThreeTokens(randomNumber, randomNumberTwo, randomNumberThree);
winTwoTokens(randomNumber, randomNumberTwo, randomNumberThree);
Lose(randomNumber, randomNumberTwo, randomNumberThree);
}
}
void welcome()
{
cout << "Welcome to the most amazing text-based Slot Machine!" << endl;
cout << "Our fine Slot Machines are rigged so that you almost never win and so that we make BILLIONS of DOLLARS!" << endl;
cout << "Anyways, You have " << tokens << "tokens" << endl;
cout << "Soooo, have fun with these few tokens as you will have none left very, very, very SOON!" << endl;
}
int main()
{
welcome();
for(int playTime = 0; playTime<30001; playTime++)
{
lever();
}
return 0;
}
the bug is that when you execute the application and you type "y" for your first set of random numbers and you get like "6 6 5" for example it will grant you your 2 tokens but then think that you lost and take away 3. After that happens once and get another set of 3 random numbers like "3 3 4", you get your 2 tokens and it doesn't take away the 3 like ti should work.
I just finished lesson 3 where it went over brief explanation of a function, how to call one, what it is to get you familiar with it but not to explain the whole 9 yards, which is in another lesson.