Thread: an if statement with error

  1. #1
    Unregistered
    Guest

    an if statement with error

    cout << "Do you wish to credit or debit your account? Enter C or D"<< endl;
    string answer;
    cin >> answer;
    cout << "how much?"<<endl;
    double amount;
    cin >> amount;
    if (answer== 'C') || answer== 'c')


    //im getting the error
    binary '==' : 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' does not define this operator or a conversion to a type ac



    Help!!! My other programs work like this!!!!

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >if (answer== 'C') || answer== 'c')
    Keep in mind that a string is not a character. The single quotes specify a test between a single character and answer, which is a string. Change the test to this and it will work:
    if (answer== "C") || answer== "c")

    -Prelude
    My best code is written with the delete key.

  3. #3
    Pygmy Monkey ErionD's Avatar
    Join Date
    Feb 2002
    Posts
    408
    Hasnt anybody noticed that theres a ) that shouldnt be there?

  4. #4
    napKINfolk.com napkin111's Avatar
    Join Date
    Apr 2002
    Posts
    310
    A ")" is missing...

  5. #5
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >Hasnt anybody noticed that theres a ) that shouldnt be there?
    Yes, that too. *blush*

    -Prelude
    My best code is written with the delete key.

  6. #6
    Registered User
    Join Date
    Apr 2002
    Posts
    139
    if I remember right, (UNREGISTERED) the problem stats that you need to get both the type of transaction and the amount at the same time. ie C 124.56 (check of 124.56) this would lead to the variables of a char and an integer. oh and check it see if the char entered is an 'E' before getting the integer in. Then you use the if then statements for that char variable. till wednesday.
    "The most common form of insanity is a combination of disordered passions and disordered intellect with gradations and variations almost infinite."

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. Testing some code, lots of errors...
    By Sparrowhawk in forum C Programming
    Replies: 48
    Last Post: 12-15-2008, 04:09 AM
  3. Making C DLL using MSVC++ 2005
    By chico1st in forum C Programming
    Replies: 26
    Last Post: 05-28-2008, 01:17 PM
  4. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 08:39 AM
  5. Linking error
    By DockyD in forum C++ Programming
    Replies: 10
    Last Post: 01-20-2003, 05:27 AM