How to check for a value in an array

Vishnu Rajendran

I have entered 4 numbers into an array using

for (int i=0;i<4;i++)
{
    cin >> choice[i];
}

I need to check whether i have entered numbers 1,3,4,6(in any order) into the array

eg:-

if choice[0] == 1 && choice[1] == 3 && choice[2] == 4 && choice[3] == 6

else if ........ 1,3,6,4

else if..........1,6,3,4

else if.......1,6,4,3

else if......1,4,6,3

else if......1,4,3,6

....
....

else if.....6,4,3,1

this type of checking makes my code too big.

Please help me with an alternative way

Danyal Sandeelo
bool count1=false;
bool count2=false;
bool count3=false;
bool count4=false;

for (int i=0;i<4;i++)
{
cin >> choice[i];
if(choice[i]==1) count1==true;
else if(choice[i]==3) count2=true;
else if(choice[i]==4) count3=true;
else if(choice[i]==6)  count4=true;
}

if(count1 && count2 && count3 && count4) cout<<endl<<"yes, it is!";

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

How can I check for the existance of an enum value in an array of Enums?

분류에서Dev

check if value exists in mongo document array

분류에서Dev

How to check if a string array is null?

분류에서Dev

How to check all members of an array

분류에서Dev

Check in an array in java if value is lower than previous value and split it

분류에서Dev

How to check for the presence of no value in a "params[:attribute]"

분류에서Dev

How to check only numbers in value - Lua

분류에서Dev

How to check radio button with radio button value

분류에서Dev

How to check if user input is not an int value

분류에서Dev

How to check if a value/property exist in JSON data

분류에서Dev

how to check for a null value in t-sql

분류에서Dev

How to check if a char array element is empty?

분류에서Dev

how to check for variable existence in array key php

분류에서Dev

How to check a 2D array diagonally?

분류에서Dev

How to check if an array exists in ListBox in C#

분류에서Dev

How to check whether a String is present in the Custom Array or not?

분류에서Dev

Loop through an array of names and check if value of keypress matches a character in a name

분류에서Dev

How to replace an object value in an array?

분류에서Dev

how to validate array value in codeigniter

분류에서Dev

How to display the highest value in an array

분류에서Dev

How to set value in array of array index

분류에서Dev

How to get array of array value count?

분류에서Dev

How to I check whether a given variable value is of type string

분류에서Dev

How to check if a ResultSet of an AJAX call using JQuery has value

분류에서Dev

How to check file integrity of download if checksum value is not posted

분류에서Dev

How to check a Radio button from the value of a table of mySQL

분류에서Dev

How to check Key Value Observing in ObjectiveC for dictionary of arrays?

분류에서Dev

How to check a class for a certain value and then return a result through Tag Manager

분류에서Dev

How Ubuntu/Linux defines value to force check disks/partitions on boot?

Related 관련 기사

  1. 1

    How can I check for the existance of an enum value in an array of Enums?

  2. 2

    check if value exists in mongo document array

  3. 3

    How to check if a string array is null?

  4. 4

    How to check all members of an array

  5. 5

    Check in an array in java if value is lower than previous value and split it

  6. 6

    How to check for the presence of no value in a "params[:attribute]"

  7. 7

    How to check only numbers in value - Lua

  8. 8

    How to check radio button with radio button value

  9. 9

    How to check if user input is not an int value

  10. 10

    How to check if a value/property exist in JSON data

  11. 11

    how to check for a null value in t-sql

  12. 12

    How to check if a char array element is empty?

  13. 13

    how to check for variable existence in array key php

  14. 14

    How to check a 2D array diagonally?

  15. 15

    How to check if an array exists in ListBox in C#

  16. 16

    How to check whether a String is present in the Custom Array or not?

  17. 17

    Loop through an array of names and check if value of keypress matches a character in a name

  18. 18

    How to replace an object value in an array?

  19. 19

    how to validate array value in codeigniter

  20. 20

    How to display the highest value in an array

  21. 21

    How to set value in array of array index

  22. 22

    How to get array of array value count?

  23. 23

    How to I check whether a given variable value is of type string

  24. 24

    How to check if a ResultSet of an AJAX call using JQuery has value

  25. 25

    How to check file integrity of download if checksum value is not posted

  26. 26

    How to check a Radio button from the value of a table of mySQL

  27. 27

    How to check Key Value Observing in ObjectiveC for dictionary of arrays?

  28. 28

    How to check a class for a certain value and then return a result through Tag Manager

  29. 29

    How Ubuntu/Linux defines value to force check disks/partitions on boot?

뜨겁다태그

보관