Thread: My best C++ Programs

  1. #76
    Registered User Paro's Avatar
    Join Date
    Feb 2002
    Posts
    160
    blackjack sounds possible...and i know how to make the characters for the types of cards... hmmm, not a bad idea but it will be kinda hard... oh well its worth a try, ill get back to you guys with a progress report
    Paro

  2. #77
    Registered User Paro's Avatar
    Join Date
    Feb 2002
    Posts
    160

    Question

    im in the process of building a blackjack game, but i must admit... it is much harder than i thought possible...

    a few problems:

    1) Aces can be 1 or 11
    2) when it comes out as 12 (queen), i made it automatically be worth 10 (which it should be) but i dont know how to make it so it outputs a Q... or maybe i say

    if(card1==12)
    card1=='Q';
    but if i did that it would add up horribly... is there any way to make it so 'Q' is worth 10 when i add it up?

    thanks for help in advance
    Paro

  3. #78
    Registered User
    Join Date
    Mar 2002
    Posts
    6
    Do you mind if I rewrite your program and post a copy as my own? I'm interested in seeing how well I can do for modifying it and make it "better" in my eyes. First year programming, myself.

  4. #79
    Registered User Paro's Avatar
    Join Date
    Feb 2002
    Posts
    160

    Talking

    hehe, do whatever you want with it. your talking about the ones at the top right? if so, its no problem
    Paro

  5. #80
    Registered User
    Join Date
    Mar 2002
    Posts
    6
    Was actually talking about the ones that started this thread. hehe... I'm working on the dice thing myself, using Member Functions and structs. Works nicely here at class.

  6. #81
    Seņor Member
    Join Date
    Jan 2002
    Posts
    560
    Hey paro, you can either use parallel arrays or a struct, but the struct is much cleaner. And the toughest part is making an efficient shuffle. I did this program after about 2 months of C++, so it's definetly possible.

  7. #82
    Registered User
    Join Date
    Jan 2002
    Posts
    11

    Re: Re: My best C++ Programs

    Originally posted by Unregistered


    first year in high shcool and thats your semester project?! wow you guys must progress slow as hell our school does stuff with stacks and binary search trees,advanced algorithms and the like...
    I doubt that, unless your school has problems with the APCS curriculum.

  8. #83
    Registered User Paro's Avatar
    Join Date
    Feb 2002
    Posts
    160

    Talking

    Raven:

    yea, those were the programs i was talking about. feel free to do whatever you want with the code and use it to your advantage, this site has helped me with many problems so it's the least i could do
    Paro

  9. #84
    Registered User Paro's Avatar
    Join Date
    Feb 2002
    Posts
    160
    tim:

    we just learned the basics of structs last week, and this week we are learning Classes...

    the basics of arrays are not until next chapter

    (note: this was 2 months ago when i made that program )
    Paro

  10. #85
    Registered User Paro's Avatar
    Join Date
    Feb 2002
    Posts
    160

    Cool

    um, anyone notice how unbelievably large this thread has gotten? over half my posts are on this thread alone...

    anyways,

    does anyone have a simple way to make it so an ACE in blackjack can be worth 1 or 11?

    in blackjack sometimes you have 5 cards because they are all low... well, i need some way to make it so you cant have 5 of the same card, and so the odds of your card appearing twice is more unlikely then it is to be a different card...

    blackjack is so unbelievably hard to do im frazzled...

    why do i always have to make my programs harder to do than i can handle? the idea was just so it would be a simple blackjack game, and its turning into a nightmare
    Paro

  11. #86
    Seņor Member
    Join Date
    Jan 2002
    Posts
    560
    Well to begin, try to think up a good shuffling algorithm. I've thought up 3 already and I'm working on a fourth using linked lists. If you do a real shuffle and actually make a deck, the same card will never appear twice. Use suits, it makes it look better. And by the way, this will be REALLY FREAKIN HARD without arrays. So go ahead and learn those first.

  12. #87
    Registered User rmullen3's Avatar
    Join Date
    Nov 2001
    Posts
    330
    Hehe, I remember the first program I really "tried" at was a game of 21. It was absolute crap- global variables and worse, it didn't even allow you to actually "play" the game...

    Code:
    #include <iostream.h>
    #include <stdio.h>
    #include <conio.h>
    #include "randoma.h"
    
    int ucard; 
    int dcard;
    int ccard;
    
    int PlayGame();
    void UpdateCount(int result, int &wins, int &losses, int&draws);
    char AskRepeat();
    void Report(int wins, int losses, int draws, int ng);
    
    int main() {
    	int wins = 0, losses = 0, draws = 0;
    	char answer; int nogame = 0;
    	do {
    		int result; nogame++;
    		result = PlayGame();
    		UpdateCount(result, wins, losses, draws);
    		answer= AskRepeat();
    			ucard = 0;
    			dcard = 0;
    			ccard = 0;
    	} while ((answer != 'N') && (answer != 'n'));
    	Report(wins, losses, draws, nogame);
    	return(0);
    }
    
    int PlayGame()
    {
    	int ncard = 0; int i = 0;
    	cout << "How many card do you want? ";
    	cin >> ncard; cout << endl << "You: ";
    	for (i = 0; i != ncard; i++) {
    		ccard= (random(10)+1);
    		ucard+=ccard;
    		cout << "  " << ccard;
    	}
    	cout << " = " << ucard;
    	cout << endl << "Computer: ";
    	for (i = 0; i != 3; i++) {
    		ccard= (random(10)+1);
    		dcard+=ccard;
    		cout << "  " << ccard;
    	}
    	cout << " = " << dcard;
    	cout << endl;
    	int tog = 0;
    	if (dcard < 22 && ucard < 22) {
    
    		if (dcard == ucard) tog = 1;
    		if (dcard > ucard) tog = 2;
    		if (ucard > dcard) tog = 3;
    
    	}
    	if (dcard > 21) tog = 4;
    	if (ucard > 21) tog = 5;
    	if (dcard > 21 && ucard > 21) tog = 6;
    	if (tog == 1 || tog == 6) cout << "\nOoh, a tie!\n";
    	if (tog == 2 || tog == 5) cout << "\nHeh, you lose.\n";
    	if (tog == 3 || tog == 4) cout << "\nYay! You win!\n";
    	return (tog);
    }
    
    void UpdateCount(int result, int&wins, int&losses, int&draws)
    {
    	switch (result) {
    	case 1: draws++; break;
    	case 2: losses++; break;
    	case 3: wins++; break;
    	case 4: wins++; break;
    	case 5: losses++; break;
    	case 6: draws++; break;
    	}
    }
    
    char AskRepeat() 
    {
    	char tstr;
    	while (tstr != 'y' && tstr != 'Y' && tstr != 'n' && tstr != 'N') {
    		cout << "\n Play again (Y/N)?  ";
    		cin >> tstr;
    	if (tstr != 'Y' && tstr != 'y' 
    		&& tstr != 'n' && tstr != 'N') {
    		cout << "Please enter yes or no." << endl; }
    	}
    	return (tstr);
    }
    
    void Report(int wins, int losses, int draws, int ng)
    {
    	system("cls");
    	cout << "\n" << "Your wins = " << wins << endl;
    	cout << "Computer wins = " << losses << endl;
    	cout << "Draws = " << draws << endl;
    	cout << "Total games = " << ng << endl;
    	cout << '\n';
    	return;
    }

  13. #88
    Registered User
    Join Date
    Mar 2002
    Posts
    2
    paro,
    you were asking if there was a simpler way to make
    it so an ACE in blackjack can be worth 1 or 11,
    well i was thinking something like this, i hope
    it helps:

    ACE = 11
    SUM = the sum of all the cards, ACE being 11

    if SUM > 21 then ACE = 1
    check SUM again
    if SUM > 21 you lose

    thought by me in a yippy!,

  14. #89
    Registered User Paro's Avatar
    Join Date
    Feb 2002
    Posts
    160

    Question

    ill try that, and i already know a little about arrays

  15. #90
    Registered User Paro's Avatar
    Join Date
    Feb 2002
    Posts
    160
    rmullen i tried your program, but i dont have the header file "randoma.h" could you show the code for that so i can try out your prog?
    Paro

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Recommend upgrade path for C programs
    By emanresu in forum C Programming
    Replies: 3
    Last Post: 11-22-2007, 07:32 AM
  2. How come Dev C++ cant run some programs??
    By Sephiroth in forum C Programming
    Replies: 41
    Last Post: 09-17-2005, 05:35 AM
  3. Way to get the current open programs displayed?
    By CPPguy1111 in forum C++ Programming
    Replies: 6
    Last Post: 06-22-2005, 12:24 AM
  4. POSIX/DOS programs?
    By nickname_changed in forum C++ Programming
    Replies: 1
    Last Post: 02-28-2003, 05:42 AM
  5. executing c++ programs on the web
    By gulti01 in forum C++ Programming
    Replies: 4
    Last Post: 08-12-2002, 03:12 AM