Forgive my ignorance. I'm still at the beginning of C++, and am having a hard time grasping the language, since it is my first.
How would I call the strings or int in a function into another function so I would be able to separate the different processes required for the program?
I'm really sorry if it's messy, from my understanding the code should work, but it is displaying nothing on the main.cpp
file.
This is a full house probability checker. I'm supposed to run a bunch of rounds and deal out five cards and check if they are a full house. Please tell me what I can improve on, and what I lack in my understanding.
class.cpp
#include <iostream>
#include "Class.h"
#include <ctime>
#include <cstdlib>
#include <string>
using namespace std;
void shufflewell()
{
srand(time(0));
int deck[52];
int i;
// deck shuffling
for(i=0; i<52; i++)
{
int j = rand() % 52;
int temp = deck[i];
deck[i] = deck[j];
deck[j] = temp;
}
}
void DisplayCard ()
{
void shufflewell();
int i;
int deck[52];
string suitnames[4]={"spades", "diamonds", "clubs", "hearts"};
string ranknames[13]={"A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"};
int suitnumber = deck[i] / 13; // 0 - 3
int rank = deck[i] % 13;
cout << ranknames[rank] << " of " << suitnames[suitnumber] << endl;
// Get the rank of the first 5 cards
int R[5]; // = {4, 7, 6, 3, 5}; // rank of the first 5 cards
int S[5];
for(i=0; i<5; i++)
{
R[i] = deck[i]%13;
S[i] = deck[i]/13;
}
cout << ranknames[R[i]] << " of " << suitnames[S[i]];
return DisplayCard();
}
// Deals five random cards to player
void dealHand()
{
for(int i = 0; i < 5; i++)
{
DisplayCard();
cout << ranknames[R[i]] << " of " << suitnames[S[i]];
}
}
main.cpp
#include <iostream>
#include <cstdlib>
#include "Class.h"
using namespace std;
int main()
{
cout << "Full house probabilty checker";
void DisplayCard();
return 0;
}
Class.h
#ifndef Class.h
#define Class.h
#include <iostream>
#include <string>
using namespace std;
class cards
{
public:
int i;
int deck[52];
std::string suitnames;
std::string ranknames;
void shufflewell();
void DisplayCard();
void dealHand();
};
#endif // Class