No output from return statement in string function

Hello, I'm trying to get my function to return the suit and rank of the card in the return function so I can test if the values can be passed. However, there is no output when compiling the program. Any help would be appreciated. Thanks!
functions.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include "card_games.h"
#include <iostream>
#include <ctime>
#include <cstdlib> 
#include <cstdio> 
#include <string>

using std::cin;
using std::cout;
using std::endl;

string StudPoker::deckFunction () {
	
	srand(time(0));

	 struct card deck[52];  
	
	const string ranks[ ] = { "Ace", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight",
        "Nine", "Ten", "Jack", "Queen", "King" };
		
	const string suits[ ] = { "Diamonds", "Hearts", "Spades", "Clubs" };

	int k = 0; 

	for ( int i = 0; i < 13; i++)
	{
		for ( int j = 0; j < 4; j++)
		{
			deck[ k ].rank = ranks[ i ];
			deck[ k ].suit = suits[ j ];
			k++;
		}
	}
	int RandIndex = rand() % 13;
	int RandIndex2 = rand() % 4;
	/*cout << ranks[RandIndex];
	cout << " of ";
	cout << suits[RandIndex2];
	*/
	return ranks[RandIndex] + " of " + suits[RandIndex2];
}

/*void StudPoker::(ranks, suits) {
	
	
}
	
*/

main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>
#include "card_games.h"

using std::cin;
using std::cout;
using std::endl;

int main(int argc, char **argv)
{
	StudPoker deckF;
	deckF.deckFunction();
	
	
	
	
	return 0;
}

card_games.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#ifndef HEADER_H
#define HEADER_H
#include <string>

using namespace std;

class StudPoker{
	
public:
	
	string deckFunction();
	//void playerHand(ranks, suits);
	struct card{
		string rank;
		string suit;
		int value;
		
	};

private: 

	string ranks;
	string suits;
	
	};

#endif // HEADER_H 

Last edited on
I don't see a single line of code anywhere in here that writes to standard output (cout). I would not expect to see output from this program.
Right, sorry, I should have rephrased the question a bit. How could I cout my
 
return ranks[RandIndex] + " of " + suits[RandIndex2];

function?
Since deckFunction returns a std::string you can print the result directly.
1
2
3
4
5
6
7
int main(int argc, char **argv)
{
    StudPoker deckF;
    std::cout << deckF.deckFunction() << std::endl;
	
    return 0;
}
Okay, great thanks! How would I pass these values to another function. I tried to do something like this in the commented out section on line 43, but I couldn't get it to work since RandIndex is an array call. So for instance, can I pass the RandIndex and RandIndex2 into something like:
 
void StudPoker::player1hand(RandIndex, RandIndex2)

Then use them to build the hand?

Thanks again for the help! I really appreciate it.
Last edited on
Topic archived. No new replies allowed.