zim1985's Profile User Rating: -----

Reputation: 74 Whiz
Group:
Contributors
Active Posts:
558 (0.37 per day)
Joined:
19-February 10
Profile Views:
9,543
Last Active:
User is offline Dec 09 2013 06:46 PM
Currently:
Offline

Previous Fields

Country:
US
OS Preference:
Windows
Favorite Browser:
Chrome
Favorite Processor:
Intel
Favorite Gaming Platform:
PC
Your Car:
Honda
Dream Kudos:
50

Latest Visitors

Icon   zim1985 has set his status

Posts I've Made

  1. In Topic: GridBagLayout Formatting Problem

    Posted 9 Dec 2013

    That was extremely helpful. I'll try messing around with other layout managers. I've just used GridBagLayout in the past and have had pretty good results getting everything to nest and fit where I want it to, so I guess it's kind of my goto for more complicated projects? Regardless, I think I'm set now and I'll be able to figure out my problems from here. Thanks again for the help and assistance!
  2. In Topic: Cannot Convert "this" pointer

    Posted 15 Nov 2013

    View Postjjl, on 15 November 2013 - 08:23 PM, said:

    Because the play function is purely virtual (no definition for the Game class), you have to set it equal to zero.

    This
    virtual void play();
    
    


    Should be this
    virtual void play() = 0;
    
    

    Ah ok. Sorry, I've never done virtual functions and such. Thank you so much for all the help. I got it running now so I can go debug finally.
  3. In Topic: Cannot Convert "this" pointer

    Posted 15 Nov 2013

    Ok that seemed to fix most of my issues. I'm getting a different error now. Here is my updated code:

    #include <iomanip>
    #include <iostream>
    #include <string>
    #include <ctime>
    #include <stdlib.h>
    
    using namespace std;
    
    class Game
    {
    	public:
    		double winnings;
    		Game() { winnings = 0; }
    		virtual void play();
    		double getWinnings() { return winnings; }
    		void addWinnings(double n) { winnings += n; }
    };
    
    class Roulette : public Game
    {
    	public:
    		virtual void play();
    	private:
    		bool isOdd(int n);
    };
    
    void Roulette::play()
    {
    	//possible problem with 00 differing from 0
    	int slots[] = {0,00,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,
    		21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36}; //size 38
    	srand((unsigned)time(NULL));
    	int num = rand() % 37;
    	int slotWin = slots[num];
    
    	double bet = 0;
    	char betChoice = ' ';
    	int slotChoice = 0;
    	char oddEvenChoice = ' ';
    
    	cout << "How much would you like to bet? ";
    	cin >> bet;
    	cout << "Would you like to bet on a number(N) or on odd/even(O)? ";
    	cin >> betChoice;
    
    	if(betChoice == 'N' || betChoice == 'n')
    	{
    		cout << "Which number(0-36 and 00) would you like to bet on? ";
    		cin >> slotChoice;
    		cout << "The wheel came up " << slotWin << endl;
    		if(slotChoice == slotWin) //picked right slot
    		{
    			cout << "You win $" << setprecision(2) << bet*35 << endl;
    			Game::addWinnings(bet*35);
    		}
    		else //picked wrong slot
    		{
    			cout << "You lose $" << setprecision(2) << bet << endl;
    			Game::addWinnings(-bet);
    		}
    	}
    	else if(betChoice == 'O' || betChoice == 'o')
    	{
    		cout << "Are you betting on even(E) or odd(O)? ";
    		cin >> oddEvenChoice;
    		cout << "The wheel came up " << slotWin << endl;
    		if(slotWin == 0 || slotWin == 00) //lose if 0 or 00 on O/E bet
    		{
    			cout << "You lose $" << setprecision(2) << bet << endl;
    			Game::addWinnings(-bet);
    		} //win O/E bet with O
    		else if(isOdd(slotWin) && (oddEvenChoice == 'O' || oddEvenChoice == 'o'))
    		{
    			cout << "You win $" << setprecision(2) << bet << endl;
    			Game::addWinnings(bet);
    		} //win O/E bet with E
    		else if(!isOdd(slotWin) && (oddEvenChoice == 'E' || oddEvenChoice == 'e'))
    		{
    			cout << "You win $" << setprecision(2) << bet << endl;
    			Game::addWinnings(bet);
    		}
    		else //lose O/E bet
    		{
    			cout << "You lose $" << setprecision(2) << bet << endl;
    			Game::addWinnings(-bet);
    		}
    	}
    	else
    		cout << "Input error.";
    }
    
    bool Roulette::isOdd(int n)
    {
    	n = n%2;
    	if(n == 1) return true;
    	else return false;
    }
    
    class ChuckALuck : public Game
    {
    	public:
    		virtual void play();
    
    };
    
    void ChuckALuck::play()
    {
    	srand((unsigned)time(NULL));
    	int dice[6]; //array of dice
    	for(int i = 0; i < 6; i++)
    		dice[i] = rand() % 6 + 1;
    
    	double bet = 0;
    	int numChoice = 0;
    	int dieCount = 0;
    
    	cout << "How much would you like to bet? ";
    	cin >> bet;
    	cout << "Which number(1-6) do you want to bet on? ";
    	cin >> numChoice;
    
    	for(int i = 0; i < 6; i++) //find the number of die that match user number
    		if(numChoice == dice[i]) dieCount++;
    
    	if(dieCount == 0) //lose
    	{
    		cout << "You lose $" << setprecision(2) << bet << endl;
    		Game::addWinnings(-bet);
    	}
    	else //win
    	{
    		cout << "You win $" << setprecision(2) << bet*dieCount << endl;
    		Game::addWinnings(bet*dieCount);
    	}
    }
    
    class Pick5 : public Game
    {
    	public:
    		virtual void play();
    	private:
    		bool hasNum(int[], int, int);
    		int numSame(int[], int[]);
    
    };
    
    void Pick5::play()
    {
    	srand((unsigned)time(NULL));
    	double bet = 0;
    
    	int playerNums[5];
    	int playerNum = 0;
    	int gameNums[5];
    	int gameNum = 0;
    
    	int same = 0;
    
    	cout << "How much would you like to bet? ";
    	cin >> bet;
    
    	for(int i = 0; i < 5; i++)
    	{
    		gameNum = rand() % 9;
    		while(hasNum(gameNums, gameNum, i)) //checks if the number is in the list
    			gameNum = rand() % 9; //gets a new random number if it is
    		gameNums[i] = gameNum;
    	}
    
    	for(int i = 0; i < 5; i++)
    	{
    		cout << "Pick a number(0-9): "; //prompt for number
    		cin >> playerNum;
    		
    		while(hasNum(playerNums, playerNum, i)) //checks if number is already in the list
    		{
    			cout << "Do not enter repeat numbers." << endl; //warning
    			cout << "Pick a number(0-9): "; //prompt again for number
    			cin >> playerNum;
    		}
    		playerNums[i] = playerNum;
    	}
    
    	same = numSame(playerNums, gameNums);
    
    	if(same < 3)
    	{
    		cout << "You lose $" << setprecision(2) << bet << endl;
    		Game::addWinnings(-bet);
    	}
    	else if(same == 3)
    	{
    		cout << "You broke even.  No win or loss.";
    	}
    	else if(same == 4)
    	{
    		cout << "You win $" << setprecision(2) << bet << endl;
    		Game::addWinnings(bet);
    	}
    	else
    	{
    		cout << "You win $" << setprecision(2) << bet*5 << endl;
    		Game::addWinnings(bet*5);
    	}
    }
    
    bool Pick5::hasNum(int nums[], int num, int size)
    {
    	bool containNum = false;
    	for(int i = 0; i < size; i++)
    		containNum = num == nums[i];
    	return containNum;
    }
    
    int Pick5::numSame(int nums1[], int nums2[])
    {
    	int same = 0;
    	for(int i = 0; i < 5; i++)
    	{
    		for(int j = 0; j < 5; i++)
    			if(nums1[i] == nums2[j]) same++;
    	}
    	return same;
    }
    
    class TheHatGame : public Game
    {
    	public:
    		int white, blue, red;
    		double total;
    		TheHatGame();
    		virtual void play();
    	private:
    		void pullWhite();
    		void pullBlue();
    		void pullRed();
    };
    
    TheHatGame::TheHatGame()
    {
    	white = 5;
    	blue = 3;
    	red = 2;
    	total = 0;
    }
    
    void TheHatGame::play()
    {
    	srand((unsigned)time(NULL));
    	int token = 0;
    	char choice = 'y';
    
    	while(choice == 'y' || choice == 'Y')
    	{
    		token = rand() % 10 + 1;
    
    		if(token >= 1 && token <= 5)
    		{
    			if(white > 0)
    				pullWhite();
    		}
    		else if(token >= 6 && token <= 8)
    		{
    			if(blue > 0)
    				pullBlue();
    		}
    		else
    		{
    			if(red > 0)
    				pullRed();
    		}
    
    		if(red < 2)
    			break;
    
    		cout << "Would you like to pick another token(Y/N)? ";
    		cin >> choice;
    	}
    
    	if(total < 0)
    		cout << "You lose $" << setprecision(2) << total << endl;
    	else
    		cout << "You win $" << setprecision(2) << total << endl;
    	
    
    }
    
    void TheHatGame::pullWhite()
    {
    	cout << "You pulled a white token." << endl;
    	white--;
    	total += 5;
    	Game::addWinnings(5);
    }
    
    void TheHatGame::pullBlue()
    {
    	cout << "You pulled a blue token." << endl;
    	blue--;
    	total += 10;
    	Game::addWinnings(10);
    }
    
    void TheHatGame::pullRed()
    {
    	cout << "You pulled a red token." << endl;
    	red--;
    	total -= 25;
    	Game::addWinnings(-25);
    }
    
    int main()
    {
    	double totalWinnings = 0;
    	char play = ' ';
    	string name = "";
    	int numRounds = 0;
    
    	cout << "What is your full name? ";
    	cin >> name;
    
    	cout << "Would you like to play a game? ";
    	cin >> play;
    
    	while(play == 'y' || play == 'Y')
    	{
    		int gameChoice = 0;
    		cout << "Which game would you like to play? " << endl;
    		cout << "1. Roulette" << endl;
    		cout << "2. Chuck-A-Luck" << endl;
    		cout << "3. Pick 5" << endl;
    		cout << "4. The Hate Game" << endl;
    		cout << "Enter game number: ";
    		cin >> gameChoice;
    
    		if(gameChoice == 1)
    		{
    			cout << "How many rounds do you want to play? ";
    			cin >> numRounds;
    			for(int i = 0; i < numRounds; i++)
    			{
    				cout << "Roulette " << i << endl;
    				Roulette r;
    				r.play();
    				totalWinnings += r.getWinnings();
    			}
    		}
    		else if(gameChoice == 2)
    		{
    			cout << "How many rounds do you want to play? ";
    			cin >> numRounds;
    			for(int i = 0; i < numRounds; i++)
    			{
    				cout << "Chuck-A-Luck " << i << endl;
    				ChuckALuck cal;
    				cal.play();
    				totalWinnings += cal.getWinnings();
    			}
    		}
    		else if(gameChoice == 3)
    		{
    			cout << "How many rounds do you want to play? ";
    			cin >> numRounds;
    			for(int i = 0; i < numRounds; i++)
    			{
    				cout << "Pick 5 " << i << endl;
    				Pick5 p5;
    				p5.play();
    				totalWinnings += p5.getWinnings();
    			}
    		}
    		else if(gameChoice == 4)
    		{
    			cout << "How many rounds do you want to play? ";
    			cin >> numRounds;
    			for(int i = 0; i < numRounds; i++)
    			{
    				cout << "The Hat Game " << i << endl;
    				TheHatGame thg;
    				thg.play();
    				totalWinnings += thg.getWinnings();
    			}
    		}
    		else
    			cout << "Please enter a number between 1 and 4";
    		
    		cout << "Would you like to play a game? ";
    		cin >> play;
    	}
    
    	if(totalWinnings < 0)
    		cout << name << " lost $" << setprecision(2) << totalWinnings << endl;
    	else
    		cout << name << " won $" << setprecision(2) << totalWinnings << endl;
    
    
    	system("pause");
    	return 0;
    }
    
    


    And here is the new error message:
    >Game.obj : error LNK2001: unresolved external symbol "public: virtual void __thiscall Game::play(void)" (?play@Game@@UAEXXZ)
    1>C:\Users\.\Desktop\CS\C++\CS 37\HW 4\Debug\HW 4.exe : fatal error LNK1120: 1 unresolved externals
    
    
  4. In Topic: Cannot Convert "this" pointer

    Posted 15 Nov 2013

    View Postjjl, on 15 November 2013 - 04:10 PM, said:

    You need to precede the base methods with game::

    i.e.
    addWinnings(bet*-35);
    
    

    should be
    game::addWinnings(bet*-35);
    
    

    I tried this but get this error now:
    The object has type qualifiers that are not compatible with the member function "Game::addWinnings"
    
    

    I don't know what to do.
  5. In Topic: Operator Overloading "Illegal for Class" error

    Posted 13 Nov 2013

    View Post#define, on 13 November 2013 - 09:12 PM, said:

    Hi, you are trying to create two variables with the same name :

    137	    int d = fract.getDenominator();
    138	    double d = fract.getDecimal();
    
    


    Which is not allowed.

    Why am I always missing the really small, stupid things these days....

    Thanks...

My Information

Member Title:
Grand Inquisitor
Age:
20 years old
Birthday:
July 22, 1993
Gender:
Location:
California
Interests:
-Programming
-Video Games
-Music
Full Name:
Mike Zrimsek
Years Programming:
5
Programming Languages:
Java, C, C++, Python

Contact Information

E-mail:
Private
Skype:
Skype  mzrimsek

Comments

zim1985 has no profile comments yet. Why not say hello?