Compare Smallest and Largest 3-Digit Numbers using Logical Operators

  • Context: C/C++ 
  • Thread starter Thread starter ineedhelpnow
  • Start date Start date
  • Tags Tags
    C++
Click For Summary

Discussion Overview

The discussion revolves around how to logically define and compare the smallest and largest 3-digit positive integers using logical operators in programming. Participants explore the criteria for identifying valid 3-digit numbers and the necessary conditions for their implementation.

Discussion Character

  • Technical explanation, Debate/contested, Homework-related

Main Points Raised

  • One participant suggests that a valid 3-digit positive integer should be defined as being greater than or equal to 100 and less than or equal to 999.
  • Another participant proposes an alternative condition that includes eliminating specific numbers like 55, 1000, and -4, but questions whether this sufficiently captures all non-3-digit positive integers.
  • A further response emphasizes that simply excluding those specific numbers does not address the broader requirement of excluding any number that is not a 3-digit positive integer.
  • There is acknowledgment of a missed condition regarding the need to eliminate all non-3-digit and non-positive numbers.

Areas of Agreement / Disagreement

Participants express differing views on the sufficiency of various conditions for defining a 3-digit positive integer. There is no consensus on the best approach to fully capture the criteria needed.

Contextual Notes

Participants have not fully resolved the implications of their proposed conditions, and there are limitations in their definitions that depend on the clarity of what constitutes a 3-digit positive integer.

ineedhelpnow
Messages
649
Reaction score
0
num is a 3-digit positive integer, such as 100, 989, or 523, but not 55, 1000, or -4.

For most direct readability, your expression should compare directly with the smallest and largest 3-digit number.

Code:
if ( (num >= 100)<STUDENT CODE> ) { 
  ...
}

so far i came up with
Code:
((num >= 100) && (?))
but i don't know how to write something that represents a 3 digit positive number?

Edit: nevermind. i figured it out to be && (num <= 999)
 
Technology news on Phys.org
Oh.
Good call!

Actually, I thought that:
Code:
((num >= 100) && (num != 55) && (num != 1000) && (num != -4))
would also work to satisfy the criteria.
 
by doing so you only eliminate those the three numbers though, right? while in fact what needs to be eliminated is any number that's not 3 digits and not positive.
 
ineedhelpnow said:
by doing so you only eliminate those the three numbers though, right? while in fact what needs to be eliminated is any number that's not 3 digits and not positive.

You're right!
I completely missed that condition.
 

Similar threads

  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 6 ·
Replies
6
Views
6K
Replies
17
Views
2K
Replies
4
Views
2K
  • · Replies 1 ·
Replies
1
Views
5K
  • · Replies 4 ·
Replies
4
Views
4K
Replies
2
Views
2K
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
Replies
3
Views
3K