Home > Back-end >  C display data based on selecting 2 inputs
C display data based on selecting 2 inputs

Time:05-29

i have a problem where i want to display data if user sends 2 numbers.

Example :

1. book
2. car
3. ship
4. train
choose program [1/2/3/4] :

i have tried with if(num_text == "1" && num_text == "2") not working and case 1 and 2 not working

if(num_text == "1" && num_text == "2") {
 // display data 1. book and 2. car if inputs 1,2 or 1/2 or 1 2
} else {
 
}

so later if the user chooses 2 then what appears is the number according to the choice.

Example inputs : 1,2 or 1/2 or 1 and 2
Output : data 1 and 2 display

i just need what if the user selects 2 numbers, and display the selected data

I'm a beginner using C , I hope you help my problem.

CodePudding user response:

The reason, why your condition if(num_text == "1" && num_text == "2") doesn't work is fact that you compare one variable with two different values. And because one string variable cannot hold two or more string values, this statement is always false. In order to make this program work correctly, you have to split input into numbers and then compare each of them.

CodePudding user response:

If I understood your task I would say to do this: Suppose you want to do something when the user inserts two numbers "x", "y", you have different options, the first is to use if/else construct So, print the message to get the inputs x, y prompted by user, and then If(x=="value you chose" & & y=="second value you chose) {statement} Else {Statement} . The second way is to use switch construct, that I suggest you see, it can be very useful Tell me if there is something I did not answer.

  •  Tags:  
  • c
  • Related