Thread: money card game

  1. #1
    Registered User
    Join Date
    May 2010
    Posts
    2

    Question money card game

    ok i hava an asignmet due an im stuck on afew things i need to know how to write a proograme tht slecets a card suit or anumber from a deck of cards an if igues the card writght i get money but if i get it wrong i can have hints like go high or go low an help would be good thnx!
    this is my programe so far!
    Code:
    #include <stdio.h>
    #include<conio.h>
    #include <time.h>
    main()
    {
           int r_pick = 0;
           int suit [4] ={3,4,5,6,};
           int card = 0;
           
           int deck [52]  ={653,654,655,656,
                            23,24,25,26,
                            33,34,35,36,
                            43,44,45,46,
                            53,54,55,56,
                            63,64,65,66,
                            73,74,75,76,
                            83,84,85,86,
                            93,94,95,96,
                            103,104,105,106,
                            743,744,745,746,
                            813,814,815,816,
                            753,754,715,716,};
                           
                           
                           do
                           { 
                            printf("\n\nPress a key to get a card \t\t ( or 'x' to exit.");
                            srand ( time(NULL));
                            
                            deck=rand() %52+1;
                            printf("n\noyur card was %d,",card);
                            suit=rand() %4+1;
                            printf("\n\nyou suit was %c,",suit);
                            }
                            
                            
                            
                            
                            sytem("pause");
                            }
    Last edited by Salem; 05-28-2010 at 09:57 AM. Reason: Added [code][/code] tags - learn to use them yourself

  2. #2
    Registered User
    Join Date
    Nov 2009
    Posts
    151
    I'm not really sure how to answer this, but it would help people read your code if you use the code tags, look at the page before you get to the forum to see more about it.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > deck=rand() %52+1;
    a) just pick something out of the deck (without the +1)

    b) Use
    suit = rand() % 4;
    rank = rand() % 13;

    It really depends which way you want to go with this.
    Either a straight deck of 52 cards, or 4 suits of 13 ranks.

    > 653,654,655,656,
    Also, you need to explain what those numbers mean.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by Salem View Post
    > > 653,654,655,656,
    Also, you need to explain what those numbers mean.
    It is probably not a coincidence that ASCII 65 is 'A', ASCII 74 is 'J', 75 is 'K', 81 is 'Q' (and in CP-whatever-it-is 3 is ♥, 4 is ♦, 5 is ♣, and 6 is ♠). 2 through 10 don't quite work though.

  5. #5
    Registered User
    Join Date
    May 2010
    Posts
    2
    ok well i thnk i gt it now tho but im havin some erors i ran with the 52 daeck of cards!
    this is my code now any sugestion are open thnx?


    #include <stdio.h>
    #include <stdlib.h>
    #include <time.h>
    #include <windows.h>
    #include<conio.h>
    main()
    {

    int entery ;
    int bank_money = 100;
    int user_money = 50;
    int r_pick = 0;
    int suit;
    int card;
    int suit_value;
    int deck_value;
    int guess_counter;
    char user_input;

    int deck [52] ={653,654,655,656,
    23,24,25,26,
    33,34,35,36,
    43,44,45,46,
    53,54,55,56,
    63,64,65,66,
    73,74,75,76,
    83,84,85,86,
    93,94,95,96,
    103,104,105,106,
    743,744,745,746,
    813,814,815,816,
    753,754,715,716,};




    {


    while (getch()!='x','y')
    {
    printf("\n\npress any key to pick a card\t (or 'x' or 'y' to exit)");
    printf("\n\n The bank money =$%d",bank_money);
    printf("\n\n the user money =$%d",user_money);
    entery=getch();
    srand(time(NULL));


    r_pick = ( rand()%51 );
    printf("\n the rondom card was = %d");
    printf("\n the array number was = %d.\n",deck[r_pick]);
    guess_counter = 0;
    card= deck[r_pick]/10;
    suit= deck[r_pick]*10;

    do
    {
    {
    printf ("\tcard was %d",card);
    printf("\tsuit = %c");
    }

    printf("\nDo you think the card is higher or lower (H\L)");
    scanf("%d",&user_input);

    if
    (user_input > r_pick)
    {
    printf("\nyou guesd to low");
    }
    else
    (user_input < r_pick)
    {
    printf("\You guesd to high");
    }

    }
    system("pause");
    }
    }










    }

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Did you see this at the bottom of your first post?
    Last edited by Salem; 05-28-2010 at 04:57 PM. Reason: Added [code][/code] tags - learn to use them yourself

    What about this?
    << !! Posting Code? Read this First !! >>

    Do you get an annoying nag screen about trying to post code without code tags? Was your workaround to disable JS rather than making your post presentable?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. High and low game
    By jualin in forum C++ Programming
    Replies: 5
    Last Post: 10-25-2009, 09:24 PM
  2. Rolodex(information manager) =>Check my Code
    By jackfraust in forum C++ Programming
    Replies: 3
    Last Post: 04-26-2009, 03:41 AM
  3. How can I access a struct (from a header file)?
    By loxslay in forum C++ Programming
    Replies: 3
    Last Post: 10-07-2006, 01:25 PM
  4. PC Game project requires c++ programmers
    By drallstars in forum Projects and Job Recruitment
    Replies: 2
    Last Post: 02-22-2006, 12:23 AM
  5. Lets Play Money Making Game
    By ggs in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 09-04-2001, 08:36 PM