I DONT WANT TO CONVERT ANYTHING :)
I'm making a small copy of poker for myself.
#include <iostream>
#include <ctime>
#include <string>
#include <cstdlib>
#include <windows.h>
using namespace std;
void welcome();
void rules();
void game();
void rateDeck(string deck[], int decksize);
bool findCard(string deck[], string card);
int main(){
srand(time(NULL));
welcome();
rules();
getchar();
game();
return 0;
}
void welcome(){
cout << "\t WELCOME \t" << endl;
cout << " TO THE POKER SIMULATOR" << endl;
cout << "\t KIND OF \t" << endl << endl;
}
void rules(){
cout << " \t RULES" << endl;
cout << "1. You get 5 cards at the beginning." << endl << "2. You can always pick more cards." << endl << "3. It's not a game. You just look at your cards and pick more." << endl << endl << "Have fun :)" << endl;
cout << endl << "PRESS ANYTHING TO START A GAME" << endl;
}
void game(){
// 24 cards
// Tr - trefl, Ka - Karo, Ki - Kier, Pi - Pik
// A - As, K - Krol, D - Dama, W - Walet, 10, 9
string cards[] = {
"TrA", "TrK", "TrD", "TrW", "Tr10", "Tr9",
"KaA", "KaK", "KaD", "KaW", "Ka10", "Ka9",
"KiA", "KiK", "KiD", "KiW", "Ki10", "Ki9",
"PiA", "PiK", "PiD", "PiW", "Pi10", "Pi9" };
string randomCard, lastCard;
bool repeat;
int decksize = 5;
string mydeck[] = {"KaA", "PiD", "KiW", "Ka10", "Pi9"};
system("cls");
cout << "My deck: " << endl;
for (int i=0; i<decksize; i++){
randomCard = cards[rand() % 24];
mydeck[i] = randomCard;
for (int j=0; j<=i-1; j++){
do{
mydeck[i] = randomCard;
if (mydeck[i]!=mydeck[j]) repeat=false;
} while(mydeck[j]==mydeck[i] && i!=0 && repeat==true);
}
if (i==0) cout << "karta nr: " << i << " " << mydeck[i] << endl;
else cout << "karta nr: " << i << " " << mydeck[i] << " Last Card:" << lastCard << endl;
lastCard = mydeck[i];
}
rateDeck(mydeck, decksize);
}
void rateDeck(string deck[], int decksize){
int royalFlush = 0;
int straightFlush = 0;
int fourOfKind = 0;
int fullHouse = 0;
int flush = 0;
int streigh = 0;
int threeOfKind = 0;
int twoPairs = 0;
int onePair = 0;
for (int i=0; i<decksize; i++){
string card[i] = { deck[i] };
if (i==decksize-1){
if( findCard(deck, decksize, "TrA") == true ) royalFlush+=1;
//&& findCard(deck, decksize, "TrK") && findCard(deck, decksize, "TrQ") && findCard(deck, decksize, "TrJ") && findCard(deck, decksize, "Tr10") ) royalFlush+=1;
}
}
}
bool findCard(string deck[], int decksize, string card){
for(int i=0; i<decksize; i++){
if(deck[i]==card) return true;
else return false;
}
}
void rateDeck(string deck[], int decksize){
for (int i=0; i<decksize; i++){
string card[i] = { deck[i] };
if (i==decksize-1){
if( findCard(deck, decksize, "TrA") == true ) royalFlush+=1;
}
}
}
Function findCard() goes through the deck and looks for a card. If it exists it return true, otherwise false. The problem is in the last line - if statement.
Result:
error: could not convert 'decksize' from 'int' to 'std::__cxx11::string' {aka'std::__cxx11::basic_string<char>'}|
Btw. function is called in another function where "deck" is "string deck[]" and "decksize" is "int decksize".
Edit1: rateDeck func is used to describe the deck. If there is a Flush or Full House (Poker names) it should show it.