void card (vector <string> &deck, string suit)
{
for (int i = 1; i <= 13; i++)
{
string blah;
if (i == 1) blah = "A";
if (i < 10) blah = i;
if (i == 10) blah = "10";
if (i == 11) blah = "J";
if (i == 12) blah = "Q";
if (i==13) blah = "K";
blah += " " +suit;
deck.push_back (blah);
}
}
cout << "\nPlease select what seat you would like to sit in."
<< "\n(Correct inputs include a single digit numbers 1 through 9)"
<< endl;
cin >> pselection;
if (pselection > 9 || pselection < 1) {
cout << "\nYou have entered an incorrect input."
<< "\nPlease select what seat you would like to sit in."
<< "\n(Correct inputs include a single digit numbers 1 through 9)"
<< endl;
cin >> pselection;
}
else {
cout << "One moment please while we shuffle the deck.";
}
Im very new and had no idea that you could do that. Also I am not trying to be efficient, I am attempting to grasp fundamentals. Ill work on efficiency later once I can actually get my vectors to print. :P
How can I go about printing a vector of strings. For example, if I wanted to print the strings (cards) push_backed to vector p1. I believe I have to make a for loop correct? I cannot find good examples of how to have the console output the elements of a vector.
I greatly appreciate your response and participation in my programing practice.
Well being efficient is part of fundamental learning. When your learn you need to think about which is better and why and by that you gain experience and smarts. It's not good to make bad practices at the beginning of programming.
Normally you can go through an array of strings like so:
1 2 3 4
for (int i = 0; i <= 9; ++i)
{
std::cout << MyStringArray[i] << std::endl; //If you use a name like that, your bound to get shot.
}
I understand your perspective. However besides Hello world this is my first C++ program. I have never taken a computer science class or what not... I thought it was a good idea to try and understand C++ syntax and basic features instead of attempting to memorize C++'s book of functions.
I dont know how placing multiple vectors within a single affects how I call upon the variables within it and wanted to avoid the issue if possible.
What I find myself doing is making a program for my math homework. I make an algorithm, ask my program a question and have it answer me. And then I find ways to optimize and make it stronger. Sometime's I'll dawdle over a function for minutes even hours trying to figure out the fastest most proper way to do something. By that I look techniques up and I implement them. I stick to standard known operations...