More Help

This is a discussion on More Help within the Game Programming forums, part of the General Programming Boards category; Ok, I spent 2 days on this problem...for my RPG, when the user chooses a profession, nothing happens, I just ...

  1. #1
    I am the worst best coder Quantrizi's Avatar
    Join Date
    Mar 2002
    Posts
    644

    More Help

    Ok, I spent 2 days on this problem...for my RPG, when the user chooses a profession, nothing happens, I just get this error:
    C:\Program Files\Microsoft Visual Studio\My Projects\RPG2k\main.cpp(54) : error C2679: binary '<' : no operator defined which takes a right-hand operand of type 'const int' (or there is no acceptable conversion)

    here's what I do for the prof choice:
    Code:
    void begin()
    {
    	user.proftype == 0;
           system("cls");
    	pcol();
    	cout << "What is your name?\n";
    	cin  >> user.name;
    	cout << "Thank you "<<user.name<<".  Please choose a class:\n\n";
    	cout << "Please Choose Your Class Type:\n"
    			"1] Thief\n"
    			"2] Cleric\n"
    			"3] Mage\n"
    			"4] Warrior\n";
    	cin  >> user.proftype;
    	while(user.proftype < 1 ||  user.proftype > 4) // <-- error line
    {
      //uses switch statments which are not posted in code here
    }
    }
    I am just wondering if someone knows the answer to this. I have tried for 2 days trying to fix it. Or if anyone knows of a better way of doing this.

  2. #2
    Registered User red_baron's Avatar
    Join Date
    May 2002
    Posts
    274
    user.proftype == 0;
    isn't it suppose to be 1 equal cause 2 equals is comparing and 1 is assigning a value, but thats the only mistake i see in your code.
    ¿Red Baron?

    "Imagination is more important than knowledge"
    -Albert Einstein (1879-1955)

    Check out my games!

    [code] /* dont forget code tags! */ [/code]

  3. #3
    I am the worst best coder Quantrizi's Avatar
    Join Date
    Mar 2002
    Posts
    644
    Nope, if I do that, I get this error:
    Code:
    C:\Program Files\Microsoft Visual Studio\My Projects\RPG\main.cpp(42) : error C2593: 'operator =' is ambiguous
    C:\Program Files\Microsoft Visual Studio\My Projects\RPG\main.cpp(54) : error C2679: binary '<' : no operator defined which takes a right-hand operand of type 'const int' (or there is no acceptable conversion)
    C:\Program Files\Microsoft Visual Studio\RPG\main.cpp(54) : error C2679: binary '>' : no operator defined which takes a right-hand operand of type 'const int' (or there is no acceptable conversion)

  4. #4
    Registered User The Dog's Avatar
    Join Date
    May 2002
    Location
    Cape Town
    Posts
    788
    Of what type is user.proftype
    Is it an int or another class type?

  5. #5
    I am the worst best coder Quantrizi's Avatar
    Join Date
    Mar 2002
    Posts
    644
    it's of a struct....here's the struct for it:
    Code:
    struct PLAYER
    {
    	apstring name;
    	apstring proftype;
    };
    PLAYER user;
    *I have apstring.h included

  6. #6
    Registered User The Dog's Avatar
    Join Date
    May 2002
    Location
    Cape Town
    Posts
    788
    Now hear dis

    I'm not sure 'bout apstring, but if it's a class then then problem
    is that the '=' operator was not overloaded to accept an int.

    Try making proftype an int rather than an apstring:
    Code:
    struct PLAYER
    {
    	apstring name;
    	int proftype;
    };
    PLAYER user;
    
    void begin()
    {
    	user.proftype = 0;
           system("cls");
    	pcol();
    	cout << "What is your name?\n";
    	cin  >> user.name;
    	cout << "Thank you "<<user.name<<".  Please choose a class:\n\n";
    	cout << "Please Choose Your Class Type:\n"
    			"1] Thief\n"
    			"2] Cleric\n"
    			"3] Mage\n"
    			"4] Warrior\n";
    	cin  >> user.proftype;
    	while(user.proftype < 1 &&  user.proftype > 4) // <-- error line
    }

  7. #7
    I am the worst best coder Quantrizi's Avatar
    Join Date
    Mar 2002
    Posts
    644
    that one screws up my loading and saving functions.....

  8. #8
    Registered User The Dog's Avatar
    Join Date
    May 2002
    Location
    Cape Town
    Posts
    788
    Well then look up the methods of apstring if it is a class.
    There should be one that returns the string/buffer. Try assigning
    to the returned pointer.

    OR

    Lookup how the '=' operator is overloaded and what it accepts.

    If it can accepet char* then you do this:
    Code:
    user.proftype = "";
    and if the [] operator was overloaded too, then you should do this
    Code:
    while(user.proftype[0] < 1 &&  user.proftype[0] > 4)

  9. #9
    I am the worst best coder Quantrizi's Avatar
    Join Date
    Mar 2002
    Posts
    644
    Originally posted by The Dog
    Well then look up the methods of apstring if it is a class.
    There should be one that returns the string/buffer. Try assigning
    to the returned pointer.

    This was already done yesterday, but no info.
    If it can accepet char* then you do this:
    Code:
    user.proftype = "";
    and if the [] operator was overloaded too, then you should do this
    Code:
    while(user.proftype[0] < 1 &&  user.proftype[0] > 4)
    The fist one (user.proftype ="";...never thought of that one, thanks....the second one I'll try first...thank you

  10. #10
    Rambling Man
    Join Date
    Jan 2002
    Posts
    1,050
    you might have to declare the struct as

    Code:
    external struct PLAYER
    {
      apstring name;
      int proftype;
    } user;
    
    //forget about doing PLAYER user...that's a waste of time
    Basically if the struct is declared in .h file and is going to be used in another file I think you might have to delcare the file as an external struct. I'm not positive, though, and I'm probably wrong because I only skimmed over the thread.

  11. #11
    I am the worst best coder Quantrizi's Avatar
    Join Date
    Mar 2002
    Posts
    644
    TechWins: You ain't wrong, but I did fix it. I had to take out the while, and the counter (user.proftype == 0). But thanks anyways.

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21