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