online compiler and debugger for c/c++

code. compile. run. debug. share.
Source Code   
Language
#include <iostream> #include <iomanip> #include <ctime> #include <ostream> #include <string> using namespace std; //declaring function names void preparation(); void drawCards(unsigned short & yourFace, char & yourSuit, unsigned short & oppFace, char & oppSuit); void displayCards(unsigned short & yourFace, char yourSuit, unsigned short & oppFace, char oppSuit, int userHands = 0); void gameResult(unsigned short yourFace, unsigned short oppFace); bool continueBattle(); /*---------------------------------------------------------------------------- Function main() is given and you should NOT change anyting in this function. -----------------------------------------------------------------------------*/ int main( ) {unsigned short yourFaceValue, opponentFaceValue; char yourSuit, opponentSuit; preparation(); do {drawCards(yourFaceValue, yourSuit, opponentFaceValue, opponentSuit); displayCards(yourFaceValue, yourSuit, opponentFaceValue, opponentSuit); gameResult(yourFaceValue, opponentFaceValue); } while (continueBattle()); cout<<"\n\n\t********** Game is over! **********\n\n"; return 0; } void preparation() { char x = 205; char y = 201; char z = 187; char m = 200; char n = 188; char p = 186; char q = 196; char w = 218; char b = 191; char c = 192; char v = 217; char f = 179; char AAA = 65; char JJJ = 74; char KKK = 75; char QQQ = 81; char one = 49; char zero = 49; } void drawCards(unsigned short & yourFace, char & yourSuit, unsigned short & oppFace, char & oppSuit) { unsigned short sequence1 = 0, sequence2 = 0; char suits1 = 0, suits2 = 0; short randomnumber1, randomnumber2; int userHands; cout << "How many hands do you wish to play\n" << endl; cin >> userHands; int counter = 0; char AAA = 65; char JJJ = 74; char KKK = 75; char QQQ = 81; char one = 49; char zero = 49; for (counter = 0; counter < userHands; counter++) { sequence1 = time(0); srand(sequence1); randomnumber1 = 3 + rand() % 4; suits1 = randomnumber1; sequence2 = time(0) + 1; srand(sequence2); randomnumber2 = 3 + rand() % 4; suits2 = randomnumber2; unsigned sequence3 = 0, sequence4 = 0; char yourFace, oppFace; short randomnumber3, randomnumber4; sequence3 = time(0); srand(sequence3); randomnumber3 = 2 + rand() % (14 - 2 + 1); yourFace = randomnumber3; sequence4 = time(0) + 1; srand(sequence4); randomnumber4 = 2 + rand() % (14 - 2 + 1); oppFace = randomnumber4; if (yourFace < 10) { yourFace = randomnumber3 + 48; } else { switch (yourFace) { case 10: yourFace = one + zero; break; case 11: yourFace = JJJ; break; case 12: yourFace = QQQ; break; case 13: yourFace = KKK; break; case 14: yourFace = AAA; break; default: break; } } // For the opponent if (oppFace < 10) { oppFace = randomnumber4 + 48; } else { switch (oppFace) { case 10: oppFace = one + zero; break; case 11: oppFace = JJJ; break; case 12: oppFace = QQQ; break; case 13: oppFace = KKK; break; case 14: oppFace = AAA; break; default: break; } } } displayCards(yourFace, yourSuit, oppFace, oppSuit, userHands); } void displayCards(unsigned short & yourFace, char yourSuit, unsigned short & oppFace, char oppSuit, int userHands) { //system("cls"); bool aBool = false; char x = 205; char y = 201; char z = 187; char m = 200; char n = 188; char p = 186; char q = 196; char w = 218; char b = 191; char c = 192; char v = 217; char f = 179; char AAA = 65; char JJJ = 74; char KKK = 75; char QQQ = 81; char one = 49; char zero = 49; for (int i = 0; i < userHands; i++) { cout << " " << y << x << x << x << x << x << x << x << x << x << x << x << x << x << x << x << x << x << x << x << x << x << x << x << x << x << x << x << x << z << endl; cout << " " << p << "\tThe card game: 'WAR' " << p << endl; cout << " " << m << x << x << x << x << x << x << x << x << x << x << x << x << x << x << x << x << x << x << x << x << x << x << x << x << x << x << x << x << n << endl; cout << endl << endl << endl; cout << "\tYour Card" << "\t\t" << "Opponent's Card" << endl; cout << " " << w << q << q << q << q << q << q << q << q << q << q << q << q << q << q << q << q << q << q << b << "\t" << w << q << q << q << q << q << q << q << q << q << q << q << q << q << q << q << q << q << b << endl; cout << " " << f << setw(2) << yourFace << " " << f << "\t" << f << setw(2) << oppFace << " " << f << endl; cout << " " << f << " " << " " << f << "\t" << f << " " << " " << f << endl; cout << " " << f << " " << " " << f << "\t" << f << " " << " " << f << endl; cout << " " << f << " " << " " << f << "\t" << f << " " << " " << f << endl; cout << " " << f << " " << " " << yourSuit << " " << f << "\t" << f << " " << " " << oppSuit << " " << f << endl; cout << " " << f << " " << " " << f << "\t" << f << " " << " " << f << endl; cout << " " << f << " " << " " << f << "\t" << f << " " << " " << f << endl; cout << " " << f << " " << " " << f << "\t" << f << " " << " " << f << endl; cout << " " << f << " " << " " << f << "\t" << f << " " << " " << f << endl; cout << " " << f << " " << " " << f << "\t" << f << " " << " " << f << endl; cout << " " << f << " " << " " << f << "\t" << f << " " << " " << f << endl; cout << " " << f << " " << " " << f << "\t" << f << " " << " " << f << endl; cout << " " << f << " " << " " << setw(2) << yourFace << f << "\t" << f << " " << " " << setw(2) << oppFace << f << endl; cout << " " << c << q << q << q << q << q << q << q << q << q << q << q << q << q << q << q << q << q << q << v << "\t" << c << q << q << q << q << q << q << q << q << q << q << q << q << q << q << q << q << q << v << endl; gameResult(yourFace, oppFace); } } void gameResult(unsigned short yourFace, unsigned short oppFace) { if (yourFace > oppFace) { cout << "You win this round!" << endl; } else { if (yourFace < oppFace) { cout << "Sorry, but you loose this round!" << endl; } else { if (yourFace == oppFace) { cout << "This is a tied round!" << endl; } } } } bool continueBattle() { bool aBool = false; cout << "Do you wish to continue? Y/N" << endl; char temp; cin >> temp; if (temp == 'y' || temp == 'Y') { aBool = true; return aBool; } else { aBool = false; cout << "Goodbye!" << endl; return aBool; exit(0); } }

Compiling Program...

Command line arguments:
Standard Input: Interactive Console Text

                

                

Program is not being debugged. Click "Debug" button to start program in debug mode.

#FunctionFile:Line
VariableValue
RegisterValue
ExpressionValue