#guys is there an more compact way of doing this in the main function

30 messages · Page 1 of 1 (latest)

astral zephyr
#
#include <iostream>

class Players {
public:

    std::string ppname = "";
    std::string pcards = {};
};

void main(){
    std::string nameone = "";
    std::string nametwo = "";
    std::string namethree = "";
    std::cout << "player one's name?" << std::endl;
    std::cin >> nameone;
    std::cout << "player two's name?" << std::endl;
    std::cin >> nametwo;
    std::cout << "player two's name?" << std::endl;
    std::cin >> namethree;
    Players playerzero;
    Players playerone;
    Players playertwo;
    playerzero.ppname = nameone;
    playerone.ppname = nametwo;
    playertwo.ppname = namethree;
}```
steady deltaBOT
#

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 tips on how to ask a good question use !howto ask.

vague karma
#

not by much. but you could add a constructor to Players that takes the name

#

then the last 6 lines become 3:

Players playerzero(nameone);
Players playerone(nametwo);
Players playertwo(namethree);
astral zephyr
#

Oh wow I see I see

#

it would help

#

but how would the constructor function look like?

#

in the class

#
class Players {
public:
    std::string pcards = {};
    std::string ppname = "";
Players(pname) {
    ppname = pname;
};
};```
#

like this?

peak flume
astral zephyr
#

ohhh thats so cool i see thank you

peak flume
#

yeah lol just noticed

vague karma
#

@astral zephyr it should also be noted that ppname will only be initialized once. it will not be initialized with "" and then ppname

#

also missing the type for the constructor parameter

astral zephyr
#

thank you! ill look at it

#

i realised that a lot of links like those

#

come from the same tutorial page

peak flume
#

i just copy pasta'd their code lol monke brain

peak flume
astral zephyr
astral zephyr
astral zephyr
#

Ill review everything from the beginning then

#

go over what i know and dont

#

thanks guys!

#

!solved