#How to format multiple functions in main?

45 messages · Page 1 of 1 (latest)

short pebble
#

Trying to cycle through and check if each function is true or false with an array.


using namespace std;

bool  containsPair(int hand[]);
bool  containsPair(int hand[]);
bool  containsTwoPair(int hand[]);
bool  containsThreeOfaKind(int hand[]);
bool  containsStraight(int hand[]);
bool  containsFullHouse(int hand[]);
bool  containsFourOfaKind(int hand[]);

const int NUM_TYPES = 5;

int main() {
    int hand[NUM_TYPES] = {};
    string handName[NUM_TYPES] = { "Card 1: ", "Card 2: ", "Card 3: ", "Card 4: ", "Card 5: " };
    
    cout << "Enter five numeric cards, no face cards. Use 2 - 9." << endl;
    for (int i = 0; i < NUM_TYPES; i++)
    {
        cout << handName[i];
        cin >> hand[i];
    }
    while (containsPair(hand) = true) {
        cout << "Pair!" << endl;

    }
    int largest = 0;
    for (int i = 1; i < NUM_TYPES; i++) {
        if (hand[i] > hand[largest]) {
            largest = i;
        }
    } 
    cout << hand[largest];
 

    return 0;
}

bool  containsPair(int hand[])
{
    return 1;
}

bool  containsTwoPair(int hand[])
bool  containsThreeOfaKind(int hand[])
bool  containsStraight(int hand[])
bool  containsFullHouse(int hand[])
bool  containsFourOfaKind(int hand[])```
timber swallowBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For more information use !howto ask.

short pebble
#

while (containsPair(hand) = true) doesn't work though. I'm not sure how to implement a bool function setup with if do while or the likes.

uneven rivet
short pebble
#

ahah!

uneven rivet
#

= is assignment operator, you use it to assign values to variables

#

also, == true is reduntant

short pebble
#

nice to know thank you lol

uneven rivet
#

while will run the loop until the expression is false, meaning you can simply do while (containsPair(hand))

short pebble
#

Gotchya

#

and then after I can do else if else if else if etc

#

?

uneven rivet
#

um, you can't do else if with while

short pebble
#

😦

uneven rivet
#

but if the while loop exits, you know the condition is either false or you broke out of it intentionally

#

so if you never break, you can simply add the other if statements afterwards

short pebble
#

so maybe while isn't the best option then if i'm just running through it once?

#

like each function once

uneven rivet
#

if you only need to run it once, don't use while

#

you might be looking for if?

short pebble
#

well, let me explain what im trying to do so I can do this right and not just jurry rig it

#

Player inputs 5 cards from a range from 2-9

#

Into an array

#

two technically

#

I want to go through separate functions to check if a hand is a straight, 4 of a kind, etc

#

and near the end, select the highest "score" or possible hand

#

If a hand matches more than one description, the program should print out the most valuable hand type only.

uneven rivet
#

yeah, if/else would be best here

short pebble
#

gotchya, yeah still learning the if else while do stuff lol

uneven rivet
#

remember that order is important, since the first if is evaluated first, then the first else if, etc

#

and once a condition is met, the other else if or else following it will be skipped

short pebble
#

how can I circumvent that if a condition IS met but the condition below would be a better hand?

#

thats the issue I thought I'd have

uneven rivet
#

well, try think of a specific ordering of the conditions in which that case wouldn't happen

short pebble
#

Im thinking some crazy like, if blah blah is true, then check if others are true, if they are true, then make that true the new true'

#

if not true, then check the next function to see if it is true. If true, then... yeah its confusing

#

Oh wait

#

What if I did it backwards?

#

I check for four of a kind first, if not true then I check for full house, if not true then check for straight etc etc

#

Are there any issues with that?

short pebble
#

Well ty for the help mate 🙂

#

!solved

timber swallowBOT
#

Thank you and let us know if you have any more questions!

#

[SOLVED] How to format multiple functions in main?

timber swallowBOT
#

@short pebble

This question thread is being automatically marked as solved.