Results 1 to 9 of 9

Thread: CPP Boolean question

  1. #1
    Join Date
    Feb 2015
    Beans
    4

    CPP Boolean question

    I'm a programming student, although my program does not offer cpp I've been redoing my other assignments in cpp. In this project i'm working on rock paper scissors.

    In ruby or C# this type of Boolean statement would work, but CPP is an angry language. lol..

    how would I do this?

    from source
    Code:
           if (user_choice == 1) && (comp_choice == 2)
        {
         cout << "You picked Rock, Computer picked Paper. COMPUTER WINS!";
         computer_wins = computer_wins +1;
         rps();
        }
    error when compiling


    Code:
    RPS.cpp: In function ‘int rps()’:
    RPS.cpp:69:33: error: expected identifier before ‘(’ token
            if (user_choice == 1) && (comp_choice == 2)
                                     ^
    RPS.cpp:69:33: error: expected ‘;’ before ‘(’ token
    michael-HP-15%
    Last edited by lisati; February 3rd, 2015 at 07:08 AM. Reason: added [CODE] and [/CODE] to aid readability

  2. #2
    Join Date
    Jun 2007
    Location
    Porirua, New Zealand
    Beans
    Hidden!
    Distro
    Ubuntu

    Re: CPP Boolean question

    Thread moved to Programming Talk.
    Forum DOs and DON'Ts
    Please use CODE tags
    Including your email address in a post is not recommended
    My Blog

  3. #3
    Join Date
    Jun 2010
    Location
    Loznica Serbia
    Beans
    126
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: CPP Boolean question

    You need to put the entire condition into parentheses:
    Code:
    if ((user_choice == 1) && (comp_choice == 2))

  4. #4
    Join Date
    Oct 2014
    Beans
    Hidden!
    Distro
    Xubuntu

    Re: CPP Boolean question

    Code:
     if (user_choice == 1) && (comp_choice == 2)
    Yes, you need to make it in a one parenthese. C++ is a modern language, but it still maintain some C syntaxes.


    Instead type it like this, and look if you find some bugs in this codes -

    Code:
    if (user_choice == 1 && comp_choice == 2) {
                  cout << "You picked Rock, Computer picked Paper. Computer Wins!\n";
                  computer_wins++;
                  rps();
             }
    Last edited by flaymond; February 3rd, 2015 at 09:26 AM.

  5. #5
    Join Date
    Feb 2015
    Beans
    4

    Re: CPP Boolean question

    Awesome! thank you very much

  6. #6
    Join Date
    Oct 2014
    Beans
    46

    Re: CPP Boolean question

    Out of interest, what are you using to learn C++? I'm always on the lookout for good resources to read

  7. #7
    Join Date
    Feb 2015
    Beans
    4

    Re: CPP Boolean question

    I haven't had the money to buy any books, I've been just attacking it (lol) one step at a time. When i run into problems Google usually solves it. I'm lucky in the sense that I've taken C# and a lot of the stuff is the same; and one of my instructors has used CPP for a long time and is very helpful.

    I'm trying to get out of using windows technology and using GNU/Linux stuff. The G++ compiler is very nice usually at telling me what to google
    I do want to pick up a good book though...

  8. #8
    Join Date
    Oct 2014
    Beans
    46

    Re: CPP Boolean question

    Well, I picked up the official book on the archive.org site. Saved me £60! I've not had the chance to read/look at it yet though.

    https://archive.org/details/TheCProg...EditionOpsylum - Downloads are on the left. Its a little technical/direct, but an excellent resource none-the-less

  9. #9
    Join Date
    Oct 2014
    Beans
    Hidden!
    Distro
    Xubuntu

    Re: CPP Boolean question

    I just get free books(legally) at IT Ebooks, there's a couple of books I use in purpose to learn C/C++ programming.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •