Cant convert float* to float in return.

I am making my first "Game" in c++. I ran into a problem already. Help pls?

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
50
51
52
53
54
55
56
57
// War Card Game! (Build 15w30)
// This is is a player vs. cpu simulatation.
// The player will press space to place the
// next card down. The side with the higher
// card of the two wins the round. First one
// to have a full deck wins! (2 low - A high)

#include <iostream>
#include <algorithm>
#include <array>
#include <random>
#include <chrono>

float cards[52];

float collectDeck() //finds full deck.
{
	int i = 0; // Counter
	int c = 1; // Number of the Card
	int s = .1;// Suit of the Card
	while(i < 52) // Makes sure only 52 cards are ran.
		{
			if(c == 13) // If a full suit is counted.
			{
				c = 0;
				s = s + .1;
			}
			
			cards[i] = (c+s);
			
			c++;
			i++;
		}
	
	return (cards);
}

float shuffleCards ()
{
	unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
	
	shuffle (cards.begin(), cards.end(), std::default_random_engine(seed));
	
	std::cout << "Shuffled Cards:";
	for (int& x: foo) std::cout << ' ' << x;
	std::cout << '\n';
	
	return (cards);
}

int main ()
{
	collectDeck();
	shuffleCards();
	
	return 0;
}


Not the full game :P
Last edited on
closed account (E0p9LyTq)
Biggest problem I can see at a quick glance:

You are declaring a C-style array as a global, float cards[52];, and using STL container iterators on that global.

Since you already have your card set at global scope why the need to declare a return type on your functions? Your cards[] array has global scope, visible everywhere.
Last edited on
Topic archived. No new replies allowed.