expected unqualified-id before 'if'
I can't figure it out, am I missing curly brackets of something?
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
|
#define pxWidth 32
#define pxHeight 32
#include <SFML/Graphics.hpp>
#include <iostream>
struct game
{
enum difficult
{
beginner, intermediate, expert
};
int row;
int column;
int mines;
difficult option = beginner;
if(option == beginner){ ///////////<-this line
row = 8;
column = 8;
mines = 10;
}
};
int main()
{
game game;
sf::RenderWindow app(sf::VideoMode(game.row* pxWidth, game.column * pxHeight), "Minesweeper", sf::Style::Titlebar | sf::Style::Close);
}
|
Last edited on
Put the code (if statement) inside a constructor. For example:
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
|
struct game
{
enum difficulty { beginner, intermediate, expert };
int row = 16 ;
int column = 16 ;
int mines = 32 ;
difficulty option ;
explicit game( difficulty level = intermediate ) : option(level) { // constructor
if( option == beginner ) {
row = 8;
column = 8;
mines = 10;
}
else if( option == expert ) {
row = 24;
column = 24;
mines = 80 ;
}
// else option == intermediate (stay with the default member initialisers)
}
};
int main() {
game g( game::beginner ) ;
// play game etc.
}
|
omg I'm so stupid i got it now thanks you
Topic archived. No new replies allowed.