Declaring and using static variables in a class

I am having a great deal of trouble declaring two static variables outside of a class. They are to be used in every class an are static. I am trying to initialize them in "Main" but keep getting

51 C:\Users\William\Documents\C++_Programming\Extreme_Fruitstand.cpp expected primary-expression before '{' token
51 C:\Users\William\Documents\C++_Programming\Extreme_Fruitstand.cpp expected `;' before '{' token

Any help would be perfect!

Thanks

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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
  /*******************************************************************************
*    Extreme Fruitstand
*
*
*
*
*
*
*******************************************************************************/


#include <iostream.h>
#include <stdlib.h>
using namespace std;

//Classes
class City
{
public:
       
      static int money;
      static int store[];
              
       
      // non static Variables
      int cocnutPrice;
      int honeydewPrice;
      int melonPrice;
      int applePrice;
      int elderberryPrice;
      int watermelonPrice;
      int cherryPrice;
      
      bool copsPresent;
      //fucntions
      // Remember Static functions can only take static variables
      int getCoconutPrice();
      int getHoneydewPrice();
      int getMelonPrice();
      int getApplePrice();
      int getElderberryPrice();
      int getWatermelonPrice();
      int getCherryPrice();
      
private:
       
};     
      
 
int main()
{

// assign the money to 1000   
City::money = 1000;

// The store is how much of each thing you have
// We start at Zer for everone
City::store = {0,0,0,0,0,0,0};

//How many days you have left Stating from 31;
int daysLeft = 31;



   
City Chicago, New_york, LosAngeles, Sheboygan, Milwaukee;

int a = 0;    
a = Chicago.getCoconutPrice();
cout << "the value of a is " << a << endl;    
    
   
    system("pause");
    return 0;
}



int City::getCoconutPrice()
{
    int random = rand() % 4000 + 1;
    int price = random + 14000;
    return price;
}
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
// #include <iostream.h>
#include <iostream>

// #include <stdlib.h>
#include <cstdlib>

using namespace std;

class City
{
public:

      static int money;
      static int store[];

      // ....

};

int City::money = 1000; // define City::money

int City::store[] = {0,0,0,0,0,0,0}; // define City::store


int main()
{
      // ...
}

Topic archived. No new replies allowed.