Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7046111
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:36:42+00:00 2026-05-28T02:36:42+00:00

I tried to test this myself before asking on the forum but my simple

  • 0

I tried to test this myself before asking on the forum but my simple code to test this didn’t seem to work.

#include <iostream>
using namespace std;

int main() {
cout << "Enter int: ";
int number;
cin >> number;
if (number==1||2||3) {
    cout << "Your number was 1, 2, or 3." << endl;
}
else if (number==4||5||6) {
    cout << "Your number was 4, 5, or 6." << endl;
}
else {
    cout << "Your number was above 6." << endl;
}
return 0;
}

It always returns the first condition. My question is, is it even possible to have more than 2 OR conditions? Or is my syntax incorrect?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T02:36:42+00:00Added an answer on May 28, 2026 at 2:36 am

    You need to code your tests differently:

    if (number==1 || number==2 || number==3) {
        cout << "Your number was 1, 2, or 3." << endl;
    }
    else if (number==4 || number==5 || number==6) {
        cout << "Your number was 4, 5, or 6." << endl;
    }
    else {
        cout << "Your number was above 6." << endl;
    }
    

    The way you were doing it, the first condition was being interpreted as if it were written like this

    if ( (number == 1) || 2 || 3 ) {
    

    The logical or operator (||) is defined to evaluate to a true value if the left side is true or if the left side is false and the right side is true. Since 2 is a true value (as is 3), the expression evaluates to true regardless of the value of number.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I tried this as a simple test: @functions { private MvcHtmlString helloWorld() { return
Hope you guys don't mind me asking this question, but I find myself at
I just tried to run my test app and I got this error: 2012-06-16
i have tried this: <?php $fileip = fopen(test.txt,r); ?> this should have opened the
I tried to make http get request with code: String username = test\\v100; String
I'm using this sort of code in my code in my Unit tests. test
I've spent a lot of time troubleshooting this myself but none of what I've
I think I'm getting ahead of myself, but I tried AJAX tutorials to read
I really wanted to figure this out myself, but my face is now hurting
I was so pleased with myself getting this to work last night without any

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.