help!

im starting to learn c++ and im looking at arrays and structures i wrote this code earlier but i seem to be getting lots of errors when I try to compile (im using code blocks btw)
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
#include <iostream>

using namespace std;

struct scoreboard
{
    char gamertag[20];

    int kills;

    int deaths;

    int score = kills * 50;

    float kdRatio = kills / deaths;
};

int main ()
{

scoreboard gamers[5]=
{
    { "juanbenavid", 68 , 10 ,}

};

cout<< gamers[0].kdRatio << "\n";
cout<< gamers[0].score;

}


Its basically just a test run of using an array of structures, each element in the array contains a structure of the players gamertag, kills, deaths, score, and kdRatio. Everytime i compile i get like 9 errors. as far as i can understand the error is when the program tries to find the kdratio and score. im not sure if im allowed to make operations like that inside a structure using its members but i dont know of any other to go about this. if anyone could help me understand where im wrong and how i could fix it it would be very apreciated.
1
2
3
4
5
scoreboard gamers[5]=
{
    { "juanbenavid", 68 , 10 ,}

};


This, is your problem. You can't do this.

You could do something similar by overloading your constructor and your = operators, but you can't do this.

You can get the same functionality with something like this
1
2
3
4
5
6
7
const int gamersSize=5;
scoreboard gamers[gamersSize];
for (int a = 0; a < gamersSize; a++){
   gamers[a].gamertag="juanbenavid";
   gamers[a].kills=68;
   gamers[a].deaths=10;
}


Untested Code
Topic archived. No new replies allowed.