Determine a menu choice without using logical operators, relational operators, or selection constructs

Logan

I am working on a program for one of my classes, and it contains a simple menu like this:

Please choose an option below:
--------------------------------
1) Calculate with just gravity
2) Calculate with net force
3) Calculate with just drag

Now, usually it would be quite simple to determine what the menu choice is, but we are not allowed to use logical operators, relational operators, or selection constructs. I've been trying to use modulus, but to no avail. Is this even possible? We essentially can only use +, -, *, /, and %. As well as simple variables. Thank you!

greedy52

I assume net force = gravity + drag, and input is one of 1, 2, or 3.

net_force = gravity + drag
result = (2 - choice) * gravity + net_force + (choice - 2) * drag
result = result / (choice % 2 + 1)
  • choice = 1 => (gravity + gravity + drag - drag) / (2) => gravity
  • choice = 2 => (net_force) / (1) => net_force
  • choice = 3 => (-gravity + gravity + drag + drag) / (2) => drag

All of +-*/% are used .

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Determine triangle type WITHOUT logical operators JAVA

From Dev

Without using conjunctions in conditions of selection operators

From Dev

Order of evaluation with mixed logical and relational operators?

From Dev

How to print 2 characters in C without using logical operators?

From Dev

Sympy: Using logical operators on relationals

From Dev

Using logical operators with excel strings

From Dev

Using Logical Operators inside NULLIF()

From Dev

Logical Operators and increment operators

From Dev

Simplifying Nested Conditionals using Logical Operators: Logical Operators are not working?

From Dev

Logical AND (&&) and OR (||) operators

From Dev

Logical AND (&&) and OR (||) operators

From Dev

Logical operators

From Dev

Logical comparison operators without control statements

From Dev

Rounding integer division without logical operators

From Dev

Using logical operators in building a Pandas DataFrame

From Dev

Several errors in Swift when using || or && logical operators

From Dev

Variable assignment using logical operators in PHP

From Dev

Using logical operators in Meteor's Spacebars

From Dev

Removing classes with jQuery using logical operators

From Dev

R - Relational Operators and Vectorization

From Dev

Relational operators evaluation result

From Dev

use relational operators in switch

From Dev

R - Relational Operators and Vectorization

From Dev

while loop with relational operators

From Dev

What is the type of the logical operators?

From Dev

Logical operators with three lists

From Dev

Logical Operators in Tweepy Filter

From Dev

Precedence of the shell logical operators &&, ||

From Dev

Combining logical operators in Ruby

Related Related

HotTag

Archive