EverCrest Message Forums
You are not logged in. Login or Register.
Author
Topic: C++ Issue.
Dr. Gee
Say it Loud, Say it Plowed!
posted 02-23-2005 09:42:38 PM
I'm getting errors off the lines i have highlighted and i don't know why. As far as i can tell from my notes the syntax is correct. The only problem i see is if strings can't be used in an if/else statement.

The errors are:

error C2784: 'bool std: :operator ==(const std: :pair<_Ty1,_Ty2> &,const std: :pair<_Ty1,_Ty2> &)' : could not deduce template argument for 'const std: :pair<_Ty1,_Ty2> &' from 'std::string'

error C2676: binary '==' : 'std::string' does not define this operator or a conversion to a type acceptable to the predefined operator


if((required == 'Y') || (required == 'y'))
if((used == 'U') || (used == 'u'))

books = atof(enrollment.data())*.67;
else
books = atof(enrollment.data())*.87;
else
if((used == 'U') || (used == 'u'))
books = atof(enrollment.data())*.38;
else
books = atof(enrollment.data())*.45;

I'm just wondering why that won't work and i can't tell from my class notes.

Dr. Gee fucked around with this message on 02-23-2005 at 09:50 PM.

Demos
Pancake
posted 02-23-2005 09:43:47 PM
The compiler is laughing at you.
"Jesus saves, Buddha enlightens, Cthulhu thinks you'll make a nice sandwich."
Dr. Gee
Say it Loud, Say it Plowed!
posted 02-23-2005 09:52:20 PM
It's not really a big deal and i can ask the proffessor tommorow, but it's just kind of irksome.

I also remembered to go back and edit to disable smilies in the post. That helped too.

Razor
posted 02-23-2005 10:00:51 PM
error C2784: 'bool std: :operator ==(const std: :pair<_Ty1,_Ty2> &,const std: :pair<_Ty1,_Ty2> &)' : could not deduce template argument for 'const std: :pair<_Ty1,_Ty2> &' from 'std::string'

error C2676: binary '==' : 'std::string' does not define this operator or a conversion to a type acceptable to the predefined operator

code:

if((required == 'Y') || (required == 'y'))
{
if((used == 'U') || (used == 'u'))
books = atof(enrollment.data())*.67;
else
books = atof(enrollment.data())*.87;
}
else
{
if((used == 'U') || (used == 'u'))
books = atof(enrollment.data())*.38;
else
books = atof(enrollment.data())*.45;
}

You might need to define the binary operator in the string.h or string.cpp file.
And for neatness, I suggest you use brackets and otherwise lest you can get some wacky errors that you normally wouldn't see.

Razor fucked around with this message on 02-23-2005 at 10:01 PM.

Astronomy is a passion...
Engineering is a love...
My job isn't a job, it's my career, and I love every minute of it: Observatory Superintendent
Naimah
In a Fire
posted 02-23-2005 10:16:23 PM
As Razor said it is good formatting practice to use braces on everything that can have them. Doing an if with only one operator inside it? Brace before on its own line and bracer after on its own line. They don't hurt your performance any and they make the code a whole lot easier to interpret. Infact when people would ask me for help I would tell them to format correctly first, matters that much.
Deathbeam Warhero
Pancake
posted 02-24-2005 02:37:18 AM
Perhaps I'm wrong, but if you're using the == operator with strings, don't you need to use double quotes, ie "y", and not single quotes, ie 'y'?
Rabidbunnylover
Pancake
posted 02-24-2005 03:16:52 AM
quote:
Deathbeam Warhero had this to say about Duck Tales:
Perhaps I'm wrong, but if you're using the == operator with strings, don't you need to use double quotes, ie "y", and not single quotes, ie 'y'?

Single quotes means it's a character.

Looks like there's no == defined between STL strings and characters. Putting double quotes should fix it.

Merp
Rabidbunnylover
Pancake
posted 02-24-2005 03:24:45 AM
quote:
Naimah stopped beating up furries long enough to write:
As Razor said it is good formatting practice to use braces on everything that can have them. Doing an if with only one operator inside it? Brace before on its own line and bracer after on its own line. They don't hurt your performance any and they make the code a whole lot easier to interpret. Infact when people would ask me for help I would tell them to format correctly first, matters that much.

That's a matter of preference. For example, the GNU Coding Standards completely disagrees with you, and the Linux Coding Style Guidelines as well as the Java Coding Conventions disagree with your brace placement.

Merp
`Doc
Cold in an Alley
posted 02-24-2005 09:36:34 AM
In this case, I see two potential problems.
  • Your outer if statement needs braces around the then portion of the code. Why? The additional if statements inside it result in more than one line of execution code associated with the outermost if condition.
  • It sounds like you're making a string equal to a character. A string is a link to an array of characters. Capture the zero-position character from the string, then equate that to the characters. It is, of course, possible that you're doing this already, and simply didn't show us that part of the code.
  • Base eight is just like base ten, really... if you're missing two fingers. - Tom Lehrer
    There are people in this world who do not love their fellow human beings, and I hate people like that! - Tom Lehrer
    I want to be a race car passenger; just a guy who bugs the driver. "Say man, can I turn on the radio? You should slow down. Why do we gotta keep going in circles? Can I put my feet out the window? Man, you really like Tide..." - Mitch Hedberg
    Please keep your arms, legs, heads, tails, tentacles, pseudopods, wings, and/or other limb-like structures inside the ride at all times.
    Please submit all questions, inquests, and/or inquiries, in triplicate, to the Department of Redundancy Department, Division for the Management of Division Management Divisions.

    Naimah
    In a Fire
    posted 02-24-2005 10:17:35 AM
    quote:
    Rabidbunnylover thought about the meaning of life:
    That's a matter of preference. For example, the GNU Coding Standards completely disagrees with you, and the Linux Coding Style Guidelines as well as the Java Coding Conventions disagree with your brace placement.

    My coding style developed for ease of seeing the layers and what is attached to those layers. I'm sure that my style is part of some convention somewhere I just don't know nor care where it would be.

    Timpofee
    Mancake
    posted 02-24-2005 11:11:41 AM
    On a tangent...
    anyone know where i can get a C++ compiler?
    Dr. Gee
    Say it Loud, Say it Plowed!
    posted 02-24-2005 01:02:19 PM
    Fixed it. Needed to put in double quotes. I did so and it runs nicely. The only part that's still irritating me is needing to hit enter twice to clear the screen. Here's what i'm using as a pause:

    cin.get(); cin.ignore();
    system("cls");

    Would just a cin.ignore() work to wait for a carriage return to move to the next line? This part doesn't really matter, just a question of style.

    The only problem i face is that we get marked down 5 points if we can't crash the program, and seeing how everything goes into strings i can't think of anything . The only thing i could think of didn't work and just returned a 0 from the decision lines (the ones in my first post) rather than crashing like i hoped.

    `Doc
    Cold in an Alley
    posted 02-24-2005 01:12:54 PM
    You lose points if your program is stable? What sort of ascinine teaching method is your professor using?

    Try just hitting enter where it asks the yes/no question. That might work. Probably not though.

    Base eight is just like base ten, really... if you're missing two fingers. - Tom Lehrer
    There are people in this world who do not love their fellow human beings, and I hate people like that! - Tom Lehrer
    I want to be a race car passenger; just a guy who bugs the driver. "Say man, can I turn on the radio? You should slow down. Why do we gotta keep going in circles? Can I put my feet out the window? Man, you really like Tide..." - Mitch Hedberg
    Please keep your arms, legs, heads, tails, tentacles, pseudopods, wings, and/or other limb-like structures inside the ride at all times.
    Please submit all questions, inquests, and/or inquiries, in triplicate, to the Department of Redundancy Department, Division for the Management of Division Management Divisions.

    Dr. Gee
    Say it Loud, Say it Plowed!
    posted 02-24-2005 01:19:39 PM
    quote:
    `Doc's unholy Backstreet Boys obsession manifested in:
    You lose points if your program is stable? What sort of ascinine teaching method is your professor using?

    Try just hitting enter where it asks the yes/no question. That might work. Probably not though.


    Tried that before i posted. It doesn't since a blank string is still a string and it just moves into the "else" part of the if/else.

    And his view on it is, "If you don't know how to break it, then you don't know how it works." I wouldn't worry too much about it but it is 5% of the project grade.

    `Doc
    Cold in an Alley
    posted 02-24-2005 01:43:23 PM
    You're going to lose points for it not accepting "Used", "used", "Yes", or "yes" as inputs. In other words, if someone types "yes", then "yes" != "y", and your program defaults to the no option.
    Base eight is just like base ten, really... if you're missing two fingers. - Tom Lehrer
    There are people in this world who do not love their fellow human beings, and I hate people like that! - Tom Lehrer
    I want to be a race car passenger; just a guy who bugs the driver. "Say man, can I turn on the radio? You should slow down. Why do we gotta keep going in circles? Can I put my feet out the window? Man, you really like Tide..." - Mitch Hedberg
    Please keep your arms, legs, heads, tails, tentacles, pseudopods, wings, and/or other limb-like structures inside the ride at all times.
    Please submit all questions, inquests, and/or inquiries, in triplicate, to the Department of Redundancy Department, Division for the Management of Division Management Divisions.

    Dr. Gee
    Say it Loud, Say it Plowed!
    posted 02-24-2005 01:53:31 PM
    I have it specified in the input screen to use "Y or N" or "U or N" for each case. There's a point of diminishing return on this one. what if they type in uSed? or USed?

    I'm not going to go for all permutations. It's easier to error-check with a do-while loop, but that wasn't a part of this assignment and it won't be looked for grading wise.

    `Doc
    Cold in an Alley
    posted 02-24-2005 01:57:44 PM
    Read what I said earlier. Have it grab the first (position zero) letter off the string, and compare it to a character. Then it doesn't matter what they type. You can also put in a loop to have it reply to any input other than those starting with 'Y' 'y' 'U' 'u' 'N' or 'n' with instructions to reenter their answer. However, that's more complicated.
    Base eight is just like base ten, really... if you're missing two fingers. - Tom Lehrer
    There are people in this world who do not love their fellow human beings, and I hate people like that! - Tom Lehrer
    I want to be a race car passenger; just a guy who bugs the driver. "Say man, can I turn on the radio? You should slow down. Why do we gotta keep going in circles? Can I put my feet out the window? Man, you really like Tide..." - Mitch Hedberg
    Please keep your arms, legs, heads, tails, tentacles, pseudopods, wings, and/or other limb-like structures inside the ride at all times.
    Please submit all questions, inquests, and/or inquiries, in triplicate, to the Department of Redundancy Department, Division for the Management of Division Management Divisions.

    Blindy.
    Suicide (Also: Gay.)
    posted 02-24-2005 03:23:15 PM
    Make a function called toUpper for gods sake. I have no idea why people will take the time to do two comparisons on every input but wont take 45 seconds to write a 3 line function.
    -Yuri-
    Pancake
    posted 02-24-2005 03:35:30 PM
    quote:
    Blindy. said this:
    Make a function called toUpper for gods sake. I have no idea why people will take the time to do two comparisons on every input but wont take 45 seconds to write a 3 line function.

    Actually thats a prewritten function in the string.h file for C.. I'm sure C++ has the same, if not a similiar header file with the same general function.

    Pesco
    Is a copyright of Peachis. Don't underestimate his pants, either.
    posted 02-25-2005 12:06:59 AM
    Who cares about whether or not it will be included in the grading, do it because it needs to be done. Especially when it comes to error handling.

    As a coder, you need to aim for stupid user proof not what the prof tells you.

    Pesco fucked around with this message on 02-25-2005 at 12:08 AM.

    Alidane
    Urinary Tract Infection
    posted 02-25-2005 12:59:35 AM
    quote:
    Pesco probably says this to all the girls:
    As a coder, you need to aim for stupid user proof not what the prof tells you.
    Unless, of course, you're given a huge assignment with no time to do it, in which case you do the bare minimum and still lose a fuckload of sleep.

    Naimah
    In a Fire
    posted 02-25-2005 01:01:57 AM
    quote:
    Pesco attempted to be funny by writing:
    Who cares about whether or not it will be included in the grading, do it because it needs to be done. Especially when it comes to error handling.

    As a coder, you need to aim for stupid user proof not what the prof tells you.


    More like aim for compiling then fix everything later.

    Toktuk
    Pooh Ogre
    Keeper of the Shoulders of Peachis Perching
    posted 02-25-2005 08:31:40 AM
    quote:
    A sleep deprived Alidane stammered:
    Unless, of course, you're given a huge assignment with no time to do it, in which case you do the bare minimum and still lose a fuckload of sleep.


    Pesco always preferred arguing with the professor about how he was right until they changed his grade. It helps him that he's been coding professionally since he was like 16 or 17, tho.

    -Tok

    All times are US/Eastern
    Hop To: