Thread: Stuck need help with Boolean Operator

  1. #1
    Registered User
    Join Date
    Jul 2014
    Location
    Central Arizona
    Posts
    61

    Stuck need help with Boolean Operator

    I'm working on a quiz from Jumping into C++ and I can't seem to get the program to compile completely. It all compiles up to the line where I want to know if Bob and Phil are both 100 years old or older. Can someone please help me figure out what I'm doing wrong.
    Code:
    #include <iostream>
    #include <string>
    using namespace std;
    int main ()
    {
    string Phil;
    string Bob;
    int agePhil = 0;
    int ageBob = 0;
    cout << "Enter an age for Phil " <<"\n";
    cin >> agePhil;
    cout << "Enter an age for Bob " << "\n";
    cin >> ageBob;
        if (agePhil == ageBob)
        cout << "Phil and Bob are the same age " << "\n";
            else if (agePhil > ageBob)
            cout << "Phil is older than Bob " << "\n";
                else if (ageBob > agePhil)
                cout << "Bob is older than Phil "<< "\n";
                    else if (agePhil=>100 && ageBob =>100)
                    cout <<" Both Phil and Bob are over 100<< years old " <<"\n";
    }

  2. #2
    Informer -Adrian's Avatar
    Join Date
    Jan 2013
    Posts
    814
    The larger than or equal operator is written as spoken, >= not =>.

  3. #3
    Registered User
    Join Date
    Jul 2014
    Location
    Central Arizona
    Posts
    61
    Thanks, I actually rewrote the program deleted a couple of the variable and got it to work. Here is the code if anyone is interested. I didn't need to include strings in this version.
    Code:
    #include <iostream>
    
    int main ()
    {
    using namespace std;
    int Phil =0;
    int Bob =0;
    cout << "Enter Phil's age" <<"\n";
    cin >> Phil;
    cout << "Enter Bob's age " <<"\n";
    cin >> Bob;
    if (Phil < Bob)
        cout << "Bob is older then Phil "<<"\n";
        else if (Phil > Bob)
        cout << "Phil is older then Bob "<<"\n";
        else if (Phil== Bob)
        cout << "Phil and Bob are the same age "<<"\n";
        if (Phil >=100 && Bob >=100)
        cout << "Phil and Bob are real old guys ";
    return 0;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. The boolean operator NOT(!)
    By Aphex in forum C Programming
    Replies: 4
    Last Post: 08-10-2010, 07:03 AM
  2. Replies: 2
    Last Post: 04-25-2010, 10:07 AM
  3. boolean operator ||
    By dunsta in forum C Programming
    Replies: 13
    Last Post: 04-25-2010, 03:32 AM
  4. operator overloading... I'm stuck
    By Trauts in forum C++ Programming
    Replies: 36
    Last Post: 12-04-2002, 10:06 AM
  5. IS_A boolean operator?
    By stolee in forum C++ Programming
    Replies: 2
    Last Post: 01-15-2002, 12:38 PM