Initializing Structures Using User Information

I am trying to make a program that works with poker (texas holdem), starting with my hands; each hand has a value from 1 to 169, and I want to be able to enter each card, and whether they are suitable or not, and these values ​​correspond to a series of structures. Here is the code so far, I can't get it to work (im a novice programmer). oh and im using 2005 visual studio by the way

#include "stdafx.h"
#include <iostream>


int main()
{
    using namespace std;


    struct FirstCard
    {
        struct SecondCard
        {

            int s;  //suited
            int n;  //non-suited

        };

        SecondCard s14;
        SecondCard s13;
        SecondCard s12;
        SecondCard s11;
        SecondCard s10;
        SecondCard s9;
        SecondCard s8;
        SecondCard s7;
        SecondCard s6;
        SecondCard s5;
        SecondCard s4;
        SecondCard s3;
        SecondCard s2;


    };

    FirstCard s14; //ace
    FirstCard s13; //king
    FirstCard s12; //queen
    FirstCard s11; //jack
    FirstCard s10;
    FirstCard s9;
    FirstCard s8;
    FirstCard s7;
    FirstCard s6;
    FirstCard s5;
    FirstCard s4;
    FirstCard s3;
    FirstCard s2;


    s14.s14.n = 169; // these are the values that each combination
    s13.s13.n = 168; // will evaluate to, would eventually have 
    s12.s12.n = 167; // hand combinations all the way down to 1
    s11.s11.n = 166;
    s14.s13.s = 165;
    s14.s13.s = 164;
    s10.s10.n = 163; //10, 10, nonsuited
    s14.s13.n = 162;
    s14.s11.s = 161;
    s13.s12.s = 160;// king, queen, suited
    s9.s9.n = 159;
    s14.s10.s = 158;
    s14.s12.n = 157;
    s13.s11.s = 156;
    s8.s8.n = 155;
    s12.s11.s = 154;
    s13.s10.s = 153;
    s14.s9.s = 152;
    s14.s11.n = 151;

    cout << "enter first card: " << endl;

    cin >> somthing?//no idea what to put here, but this would somehow
            //read out the user input (a number from 2 to 14)
            //and assign it to the corresponding struct

    cout << firstcard.secondcard.suited_or_not << endl; //this would change depending
                                                            //on what the user inputs
    system("Pause");

} 
+3
source share
1 answer

, , (). ++ , . .

: , - , - .

, , , :

struct Values {
    unsigned suited;
    unsigned unsuited;
    Values() : suited(0), unsuited(0) {} // some default
};

, :

typedef std::map<unsigned, Values> SecondCardMap;
typedef std::map<unsigned, SecondCardMap> CardMap;

:

CardMap cards;
cards[14][14].unsuited = 169;
cards[13][13].unsuited = 168;

:

unsigned first, second;
std::cout << "enter first: ";
std::cin >> first;
std::cout << "enter second: ";
std::cin >> second;

:

cards[first][second].unsuited = 1234;

, ..

+2

Source: https://habr.com/ru/post/1742727/


All Articles