C/C++ Compare Smallest and Largest 3-Digit Numbers using Logical Operators

  • Thread starter Thread starter ineedhelpnow
  • Start date Start date
  • Tags Tags
    C++
AI Thread Summary
The discussion centers on defining a 3-digit positive integer in programming, specifically using conditional statements. The initial focus is on ensuring the number is at least 100, leading to the realization that it also needs to be less than or equal to 999 to meet the criteria for a 3-digit number. A participant initially considers excluding specific numbers like 55, 1000, and -4 but recognizes that the solution should instead encompass all non-3-digit and non-positive integers. The consensus emphasizes the importance of correctly defining the range of valid integers rather than just excluding a few specific values.
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.
 
Thread 'Star maps using Blender'
Blender just recently dropped a new version, 4.5(with 5.0 on the horizon), and within it was a new feature for which I immediately thought of a use for. The new feature was a .csv importer for Geometry nodes. Geometry nodes are a method of modelling that uses a node tree to create 3D models which offers more flexibility than straight modeling does. The .csv importer node allows you to bring in a .csv file and use the data in it to control aspects of your model. So for example, if you...
I tried a web search "the loss of programming ", and found an article saying that all aspects of writing, developing, and testing software programs will one day all be handled through artificial intelligence. One must wonder then, who is responsible. WHO is responsible for any problems, bugs, deficiencies, or whatever malfunctions which the programs make their users endure? Things may work wrong however the "wrong" happens. AI needs to fix the problems for the users. Any way to...
Back
Top