0

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!

Logan
  • 926
  • 1
  • 10
  • 18

2 Answers2

1

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 .

greedy52
  • 1,345
  • 9
  • 8
0

Well use String to take input and compare them using strcmp function Here is how to compare strings in C

Note : I'm using if/else but not using any logical operator, hope this helps

// Take string input
if(strcmp("1",input))
     // Calculate with just gravity
else if(strcmp("2",input))
     // Calculate with net force
else if(strcmp("3",input))
     // Calculate with just drag
Community
  • 1
  • 1
Mirwise Khan
  • 1,317
  • 17
  • 25