0

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.

Juliano
  • 41
  • 6
  • 7
    A [mcve] should be enough code that demonstrates the problem, and others can just copy-and-paste it into their foo.cpp file to reproduce. (With all the `#include` and a `main`.) The snippet given would require adding a lot more surrounding code, which has a chance of missing the bug in the code in question. – Eljay Jun 02 '20 at 16:54
  • 4
    Please provide an [mcve]. We need to be able to copy/paste the code into our environments. – Stephen Newell Jun 02 '20 at 16:54
  • 3
    Not related to your error, but there's a logic error in your `for` loop. It should only `return false;` after the end of the loop, not as part of an `else` – ChrisMM Jun 02 '20 at 16:54
  • 2
    I'm not seeing where you are trying to convert from int to std::string. Can you post more code? – edtheprogrammerguy Jun 02 '20 at 16:57
  • Im not trying to convert anything. I want to check if in my deck there is certain card. I dont think this needs any include functions except string. I will edit post in a minute with more code. – Juliano Jun 02 '20 at 17:08
  • 1
    I'm not seeing an error in what you've posted: https://godbolt.org/z/vdHQNG – ChrisMM Jun 02 '20 at 17:22
  • Added code. Everything worked untill I added it. Any suggestions? – Juliano Jun 02 '20 at 17:22
  • @Juliano: The code you posted works fine. The bug is in the code you didn't post. This is why its _critical_ that you post a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example) – Mooing Duck Jun 02 '20 at 17:28
  • 1
    Use `std::vector`, pass it by `const&`, and drop the now-pointless `size` args. – underscore_d Jun 02 '20 at 17:29
  • Ok im putting all of my code. Dont judge my skills - still learning :) – Juliano Jun 02 '20 at 17:35
  • I think this has sufficient clarity to be opened again. Juliano, you MAY have the option to "request reopen" on your question? Not entirely sure. I don't have enough rep to reopen it myself. – JohnFilleau Jun 02 '20 at 17:45
  • 3
    But pending the ability to give a proper answer, your prototype for `findCard` is `bool findCard(string deck[], string card);`. When you call `findCard` in `rateDeck` its looking for a function like `bool findCard(string deck[], string card);` it sees you trying to pass an int as the second parameterand gets confused. Update your prototype to match the actual implementation. – JohnFilleau Jun 02 '20 at 17:47
  • 3
    `findCard` is declared as `bool findCard(string deck[], string card);` with a `std::string` as second parameter. The definition `bool findCard(string deck[], int decksize, string card)` has a different sighnature. I'd call that a typo. – Lukas-T Jun 02 '20 at 17:48
  • Just another reason to use a `vector` instead of a pointer (decayed from an array) and size! Btw, you'll also want to pass strings by `const&` too; don't waste CPU time copying. I cast the final needed vote to reopen, but I might vote to close as typo if I only could 0:-) – underscore_d Jun 02 '20 at 18:15
  • Lol, thanks. Weird I didnt notice it. – Juliano Jun 02 '20 at 18:25

0 Answers0