Make it stop!

This is a discussion on Make it stop! within the C++ Programming forums, part of the General Programming Boards category; Ok, ive been slaving over this for hours, and it finally works, sorta. Ive written a program using the cards ...

  1. #1
    Registered User
    Join Date
    Sep 2001
    Posts
    5

    Make it stop!

    Ok, ive been slaving over this for hours, and it finally works, sorta. Ive written a program using the cards class (cards.h) that deals 5 cards 10000 times and spits back out the number of flushes that were dealt. Say there were 18, instead of printing 18 it fills the screen with 18's and keeps going. I cant get it to stop! HEEEELP!
    Here's the code (keep in mind , i am a beginner).

    #include "cards.h"

    void printcard(int suit);

    int hearts = 0;
    int diamonds = 0;
    int spades = 0;
    int clubs = 0;
    int counter = 0;
    int shuffle = 0;
    //precondition : suit is in the range 1..4,
    //post condition: prints the suit of the card



    void main()
    {

    cards deck; // declare a Cards object
    int card; // three digit number representing the card
    int suit; //1 = hearts, 2 = diamonds, 3 = clubs, 4 = spades

    while (shuffle <=10000)
    {
    deck.shuffle(); // shuffle the deck;

    // deal five cards

    for (int i = 1; i <= 5; i++)
    {

    card = deck.deal();
    suit = card/100;
    printcard(suit);
    }
    cout << counter << endl;
    } ///this closes while

    } ///added to close main

    void printcard(int suit)
    {

    if (suit == 1) {

    hearts++;
    } else if (suit ==2) {

    diamonds++;
    } else if (suit ==3) {

    clubs++;
    } else {

    spades++;
    }

    if (hearts ==5) {
    counter++;
    }

    if (diamonds ==5) {
    counter++;
    }
    if (clubs ==5) {
    counter++;
    }
    if (spades ==5) {
    counter++;

    } ///close if

    } // closes printcard

  2. #2
    Registered User EvenFlow's Avatar
    Join Date
    Oct 2001
    Posts
    422
    First don't use void main, use int main. Second, there doesn't appear to be any return value to terminate the program - put in return 0; the line above where you have commented "// added to close main".

    See if this works. If not, then could you post your cards.h file as well?
    Ramble on...

  3. #3
    Registered User
    Join Date
    Sep 2001
    Posts
    5
    No dice, same thing. Here's the card.h file as requested
    #include <iostream.h>
    #include <stdlib.h>
    #include <time.h>
    class cards
    {
    private:
    int deck[53];
    int card;

    public:
    cards();

    void shuffle();

    int deal();

    int remaining();

    };



    cards::cards()
    {

    int rn;
    int temp;
    srand(clock());
    for (int i = 1; i <= 13; i++)
    {
    deck [i] = 100+i;
    deck[i+13] = 200+i;
    deck[i + 26] = 300+i;
    deck[i + 39 ] = 400+i;
    }
    for (int i = 1; i <= 52; i++)
    {
    rn = rand()%52 + 1;
    temp = deck[i];
    deck[i] = deck[rn];
    deck[rn] = temp;
    }
    card = 0;
    }

    void cards::shuffle()
    {

    for (int i = 1; i <= 52; i++)
    {
    int rn = rand()%52 + 1;
    int temp = deck[i];
    deck[i] = deck[rn];
    deck[rn] = temp;
    }
    card = 0;
    }

    int cards::deal()
    {
    card ++;
    return deck[card] ;
    }

    int cards::remaining()
    {
    return (52-card);
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Why does my prog just stop?
    By Queatrix in forum Windows Programming
    Replies: 4
    Last Post: 03-01-2006, 05:12 PM
  2. Win32 Common Controls in C++, how do i make and use them?
    By C+noob in forum Windows Programming
    Replies: 6
    Last Post: 01-09-2006, 11:53 AM
  3. want to make this small program...
    By psycho88 in forum C++ Programming
    Replies: 8
    Last Post: 11-30-2005, 02:05 AM
  4. 'functions' in make?
    By mart_man00 in forum C Programming
    Replies: 1
    Last Post: 06-21-2003, 03:16 PM
  5. Make Cortana Stop Kicking Me!!!???
    By drdroid in forum C++ Programming
    Replies: 6
    Last Post: 02-27-2003, 05:27 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21