0

How do i give any options for user in C language

Hi, i wanna give the user to choose one of the options then the next statement will be executed as per the option chosen by user and how dothat?

9th Jan 2020, 12:12 PM
SR33N3SH
SR33N3SH - avatar
1 Answer
+ 2
Use an if-statement or a switch-statement. Use a variable to keep track of their decision (easiest is probably an integer, for a simple calculator char could be utilized, strings are also viable options but require more work, it's really up to you in the end). Present them their options, then ask them which one they want, and store their answer in your variable. Then all you have to do is compare the variable to the options you provided. If you decide to use a string to store their answer, you have to use an if-statement, otherwise a switch-statement might seem more appropriate. Further improvable by putting the first part inside a loop so if they choose a non-provided option, you inform them about their error and present them the viable options again, until they choose one of the options you provided.
9th Jan 2020, 12:20 PM
Shadow
Shadow - avatar