"cout" side affect ?

Thanks for reading...
the below code works fine (not the most efficient, i am new to c++), but as soon as one of the lines containing "cout" is removed, the calculation for those variables are all wrong ! Can someone point me to the right 'bug' ?

Thanks

//============================================================================
// Name : game2.cpp
// Author : nmn
// Version :
// Copyright : Your copyright notice
// Description : Card in C++, Ansi-style
//============================================================================

#include <iostream>
#include <iomanip>
#include <fstream>
#include <stdlib.h>
#include <time.h>
#include "card.h"
#include "deck.h"
#include "hand.h"

using namespace std;
ofstream csis;

int main() {
srand((unsigned)time(NULL));
Deck cardDeck; // get a deck of card.
Hand currentHand; // create a hand of 5 cards.
float pairPercentage;
float flushPercentage;
int pair;
int flush;
float totalPairPercentage;
float totalFlushPercentage;

csis << setiosflags(ios::showpoint | ios::fixed) << setprecision(2);
csis.open("csis2.txt");
csis <<"Trial No.\t" << "Hands Dealt\t" << "Hands w/ Pair\t" << "Percentage\t" << "Flush Hand\t" << "Percentage " << endl;

// 10 trials
for (int trial = 1; trial <=10; trial++)
{
int tempPair = 0;
int tempFlush = 0;
int hands;
cout <<"1. " <<totalPairPercentage <<" " << pairPercentage << endl;

// deal 10000 hands
for (hands = 1; hands < 10000; hands++)
{
cardDeck.shuffle(100); // shuffle card.
currentHand.dealCard(cardDeck);

pair = currentHand.checkForPair(); // check for pair
if (pair == 1)
{
tempPair = (tempPair + pair);
}

flush = currentHand.checkForFlush(); // check for flush
if (flush == 1)
{
tempFlush = (tempFlush + flush);
}
currentHand.addCard(cardDeck);
} // end 10000
pairPercentage = ((float)tempPair/hands) * 100;
flushPercentage = ((float)tempFlush/hands) * 100;
totalPairPercentage = totalPairPercentage + pairPercentage;
cout <<"2. " <<totalPairPercentage <<" " << pairPercentage << endl;

totalFlushPercentage += flushPercentage;
csis <<trial<<"\t\t"<<hands<<"\t\t"<<tempPair<<"\t\t"<<pairPercentage<<"%\t\t"<<tempFlush<<"\t\t"<<flushPercentage<<"%"<< endl;
} // end trial

csis<<"\n\n"<<endl;
csis << "Percentage of pair for 100000 hands: "<<totalPairPercentage/10<<"% "<< endl;
csis << "Percentage of flush for 100000 hands: "<<totalFlushPercentage/10<<"% "<< endl;
csis.close();
return 0;

}

http://www.cplusplus.com/forum/articles/40071/#msg216313
I haven't got `card.h' file.

You are describing undefined behaviour. Probably you are using a variable that was no initialized
Thanks ne555....you were right
Topic archived. No new replies allowed.