int main()
/*
Enter a number of hands to generate:
> 2
Ace of Diamonds, 6 of Hearts, 4 of Spades, 2 of Spades
Queen of Hearts, Queen of Hearts
Save generated hands to file? (yes/no)
> yes
File saved as Hands.txt
*/
{
cout << "This program will simulate a five card stud poker \n"
<< "hand placing you against the computer. The deck of \n"
<< "cards will be shuffled and you will be dealt five \n"
<< "random cards as your hand and the computer player \n"
<< "will also be dealt five random cards. You will then \n"
<< "be asked if you won or lost based on the rules of \n"
<< "which will be displayed. The program will then ask \n"
<< "you if you would like to save your hand for later \n"
<< "reflection\n\n"
<< "Would you like to continue? \n"
<< "Press 1 if you would like to continue.\n"
<< "Press 2 if you would like to exit the program.\n";
cin >> choice;
{
if (choice = 2)
{
cout << "The program will now end. Have a nice day! Goodbye!\n";
return 0;
}
}
}
void initializeDeck (int *cards)
if (choice = 1)
{
for (int i = 0; i < numCards; i++)
{
*cards = i;
cards++;
}
void swapCards (int *cards, int a, int b)
{
int temp = cards[a];
cards[a] = cards[b];
cards[b] = temp;
}
void shuffle (int *cards)
{
srand(time(NULL));
for (int i = 0; i < numCards; i++)
{
int randomPosition = rand() % numCards;
// cout << "random position = " << randomPosition << "\n";
swapCards(cards, i, randomPosition);
}
}
You're formatting is really bad, and can you put you code in tags please?
Because of your formatting and lack of indenting it's difficult to spot stuff like this:
1 2 3 4 5 6 7 8 9 10 11 12
void initializeDeck (int *cards) // <-- you should have an opening brace there
if (choice = 1) // <-- you want a double equals here, not just one
{
for (int i = 0; i < numCards; i++)
{
*cards = i;
cards++;
}
...
...
stuff like that.
Get your code formatted and indented properly and i'm sure you'll spot issues like this more easily
edit:
you also have 2 main functions, which is not good either.
Thank you very much sir, I have cleaned up the brackets a bit and I am now trying to get the final piece of my project. I must have it write the data to a text file. The //(commented out code) is causing the error. I it is saying that the function was not declared and I figure that is the problem exactly. I need to figure out how to pull my card hands form the function and write them to my Handofcards.txt file? Do you have any suggestions. Your input would be greatly appreciated. Thank you for your time.
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <string>
#include <fstream>
#include <cmath>
usingnamespace std;
int cardsPerSuit = 13;
int numCards = 52;
int sizeOfHand = 5;
int sizeOfHand2 = 10;
string suits[] = {"Spades", "Hearts", "Clubs", "Diamonds"};
void initializeDeck (int *cards)
{
for (int i = 0; i < numCards; i++)
{
*cards = i;
cards++;
}
}
void swapCards (int *cards, int a, int b)
{
int temp = cards[a];
cards[a] = cards[b];
cards[b] = temp;
}
void shuffle (int *cards)
{
srand(time(NULL));
for (int i = 0; i < numCards; i++)
{
int randomPosition = rand() % numCards;
// cout << "random position = " << randomPosition << "\n";
swapCards(cards, i, randomPosition);
}
}
void printCardName(int cardIndex)
{
int cardNumber = cardIndex % cardsPerSuit + 1;
string cardNumberString;
if (cardNumber == 1)
{
cardNumberString = "Ace";
}
elseif (cardNumber == 10)
{
cardNumberString = "10";
}
elseif (cardNumber == 11)
{
cardNumberString = "Jack";
}
elseif (cardNumber == 12)
{
cardNumberString = "Queen";
}
elseif (cardNumber == 13)
{
cardNumberString = "King";
}
else
{
cardNumberString = string(1, '0' + cardNumber);
}
cout << cardNumberString << " of " << suits[cardIndex / 13];
}
void printHand (int *cards)
{
cout << "YOUR CARDS" << "\n";
for (int i = 0; i < sizeOfHand; i++)
{
printCardName(cards[i]);
cout << "\n";
}
cout << "\n\nCOMPUTER PLAYERS CARDS" << "\n";
for (int i = 0+5; i < sizeOfHand2; i++)
{
printCardName(cards[i]);
cout << "\n";
}
}
int main()
{
cout << "This program will simulate a five card stud poker \n"
<< "hand placing you against the computer. The deck of \n"
<< "cards will be shuffled and you will be dealt five \n"
<< "random cards as your hand and the computer player \n"
<< "will also be dealt five random cards. You will then \n"
<< "be asked if you won or lost based on the rules of \n"
<< "poker which will be displayed. The program will then \n"
<< "save your hand for later reflection.\n\n"
<< "Pless press enter to continue.\n";
cin.get();
{
int deck[52];
initializeDeck(deck);
shuffle(deck);
printHand(deck);
}
{
cout << "Your hand has been saved to the file named Handofcards.txt\n"
<< "Thank you for playing the game!\n";
//ofstream myfile;
//myfile.open ("Handofcards.txt");
//myfile << CardName(cards[i]);
//myfile.close();
}
return 0;
}
On line 122 your compiler is telling you there is no such "CardName" method.
Here you want something similar to your "void printHand (int *cards)" method, whereby you pass your cards in and rather print to the screen you write to a file.
I'm at a wall. lol I have tried moving around all the different types I know and learned but all keep creating same kind of error. Its like the function is not being recognized. Thank you very much for your assistance. It's greatly appreciated.