How to use more than 1 condition in one “if” function?How do you set, clear, and toggle a single bit?How do function pointers in C work?problem with flushing input stream CImprove INSERT-per-second performance of SQLite?Why are elementwise additions much faster in separate loops than in a combined loop?Interleaving of putchar() and printf() functionsC: Function not returning value to mainwhy do we have a pointer to a constant in the syntax of scanf and printf functions?c - how gets() work after scanf?How to read character with scanf in C? Getting “spurious trailing ‘%’ in format [-Wformat=]”

Does the UK parliament need to pass secondary legislation to accept the Article 50 extension

Are Captain Marvel's powers affected by Thanos' actions in Infinity War

PTIJ: Haman's bad computer

Creepy dinosaur pc game identification

Fear of getting stuck on one programming language / technology that is not used in my country

How to explain what's wrong with this application of the chain rule?

How to rewrite equation of hyperbola in standard form

What happens if you are holding an Iron Flask with a demon inside and walk into an Antimagic Field?

How do apertures which seem too large to physically fit work?

Multiplicative persistence

Redundant comparison & "if" before assignment

How to cover method return statement in Apex Class?

Using substitution ciphers to generate new alphabets in a novel

Why does the Sun have different day lengths, but not the gas giants?

Unexpected behavior of the procedure `Area` on the object 'Polygon'

What should you do when eye contact makes your subordinate uncomfortable?

How much character growth crosses the line into breaking the character

Is there an injective, monotonically increasing, strictly concave function from the reals, to the reals?

Is there a RAID 0 Equivalent for RAM?

Why can Carol Danvers change her suit colours in the first place?

How do you make your own symbol when Detexify fails?

Does malloc reserve more space while allocating memory?

How do you respond to a colleague from another team when they're wrongly expecting that you'll help them?

Can disgust be a key component of horror?



How to use more than 1 condition in one “if” function?


How do you set, clear, and toggle a single bit?How do function pointers in C work?problem with flushing input stream CImprove INSERT-per-second performance of SQLite?Why are elementwise additions much faster in separate loops than in a combined loop?Interleaving of putchar() and printf() functionsC: Function not returning value to mainwhy do we have a pointer to a constant in the syntax of scanf and printf functions?c - how gets() work after scanf?How to read character with scanf in C? Getting “spurious trailing ‘%’ in format [-Wformat=]”













0















I want to change the value of _"ans"_ in every condition of this script:



main()
char in;
int ans=0;
printf ("Enter character");
scanf ("%c",&in);
if (in == '+' && in == '/' && in == '*' && in == '-')
ans=10;




How do I do that?










share|improve this question



















  • 2





    You want to replace && with ||.

    – William Pursell
    Mar 8 at 1:58











  • The next class will teach you with the || (or) operator.

    – Geno Chen
    Mar 8 at 1:59






  • 2





    if is not a function. It is a conditional statement. en.wikipedia.org/wiki/…

    – Pablo
    Mar 8 at 2:03
















0















I want to change the value of _"ans"_ in every condition of this script:



main()
char in;
int ans=0;
printf ("Enter character");
scanf ("%c",&in);
if (in == '+' && in == '/' && in == '*' && in == '-')
ans=10;




How do I do that?










share|improve this question



















  • 2





    You want to replace && with ||.

    – William Pursell
    Mar 8 at 1:58











  • The next class will teach you with the || (or) operator.

    – Geno Chen
    Mar 8 at 1:59






  • 2





    if is not a function. It is a conditional statement. en.wikipedia.org/wiki/…

    – Pablo
    Mar 8 at 2:03














0












0








0








I want to change the value of _"ans"_ in every condition of this script:



main()
char in;
int ans=0;
printf ("Enter character");
scanf ("%c",&in);
if (in == '+' && in == '/' && in == '*' && in == '-')
ans=10;




How do I do that?










share|improve this question
















I want to change the value of _"ans"_ in every condition of this script:



main()
char in;
int ans=0;
printf ("Enter character");
scanf ("%c",&in);
if (in == '+' && in == '/' && in == '*' && in == '-')
ans=10;




How do I do that?







c






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 8 at 5:17









Emma

1,0271819




1,0271819










asked Mar 8 at 1:55









SaurabhSaurabh

6012




6012







  • 2





    You want to replace && with ||.

    – William Pursell
    Mar 8 at 1:58











  • The next class will teach you with the || (or) operator.

    – Geno Chen
    Mar 8 at 1:59






  • 2





    if is not a function. It is a conditional statement. en.wikipedia.org/wiki/…

    – Pablo
    Mar 8 at 2:03













  • 2





    You want to replace && with ||.

    – William Pursell
    Mar 8 at 1:58











  • The next class will teach you with the || (or) operator.

    – Geno Chen
    Mar 8 at 1:59






  • 2





    if is not a function. It is a conditional statement. en.wikipedia.org/wiki/…

    – Pablo
    Mar 8 at 2:03








2




2





You want to replace && with ||.

– William Pursell
Mar 8 at 1:58





You want to replace && with ||.

– William Pursell
Mar 8 at 1:58













The next class will teach you with the || (or) operator.

– Geno Chen
Mar 8 at 1:59





The next class will teach you with the || (or) operator.

– Geno Chen
Mar 8 at 1:59




2




2





if is not a function. It is a conditional statement. en.wikipedia.org/wiki/…

– Pablo
Mar 8 at 2:03






if is not a function. It is a conditional statement. en.wikipedia.org/wiki/…

– Pablo
Mar 8 at 2:03













2 Answers
2






active

oldest

votes


















5














if (A && B)… does not mean:



  • do this if A is true, and

  • do this if B is true.

It means:



  • do this if A is true and B is true.

To make a condition so the if is triggered if A is true and is triggered if B is true, you use A || B. This means:



  • do this if A is true or B is true.





share|improve this answer






























    2














    In the end, you'll probably want a switch case.



    main()

    char in;
    int ans=10;
    printf ("Enter character");
    scanf ("%c",&in);
    switch(in)
    case '+':
    ans=ans+10;
    break;
    case '-':
    ans=ans-10;
    break;
    case '/':
    ans=ans/10;
    break;
    case '*':
    ans=ans*10;
    break;





    Further steps in the exercise are probably going to be to parse the input factors to the calculations as well, rather than just multiplying static ans with 10.






    share|improve this answer
























      Your Answer






      StackExchange.ifUsing("editor", function ()
      StackExchange.using("externalEditor", function ()
      StackExchange.using("snippets", function ()
      StackExchange.snippets.init();
      );
      );
      , "code-snippets");

      StackExchange.ready(function()
      var channelOptions =
      tags: "".split(" "),
      id: "1"
      ;
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function()
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled)
      StackExchange.using("snippets", function()
      createEditor();
      );

      else
      createEditor();

      );

      function createEditor()
      StackExchange.prepareEditor(
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader:
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      ,
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      );



      );













      draft saved

      draft discarded


















      StackExchange.ready(
      function ()
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55055652%2fhow-to-use-more-than-1-condition-in-one-if-function%23new-answer', 'question_page');

      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      5














      if (A && B)… does not mean:



      • do this if A is true, and

      • do this if B is true.

      It means:



      • do this if A is true and B is true.

      To make a condition so the if is triggered if A is true and is triggered if B is true, you use A || B. This means:



      • do this if A is true or B is true.





      share|improve this answer



























        5














        if (A && B)… does not mean:



        • do this if A is true, and

        • do this if B is true.

        It means:



        • do this if A is true and B is true.

        To make a condition so the if is triggered if A is true and is triggered if B is true, you use A || B. This means:



        • do this if A is true or B is true.





        share|improve this answer

























          5












          5








          5







          if (A && B)… does not mean:



          • do this if A is true, and

          • do this if B is true.

          It means:



          • do this if A is true and B is true.

          To make a condition so the if is triggered if A is true and is triggered if B is true, you use A || B. This means:



          • do this if A is true or B is true.





          share|improve this answer













          if (A && B)… does not mean:



          • do this if A is true, and

          • do this if B is true.

          It means:



          • do this if A is true and B is true.

          To make a condition so the if is triggered if A is true and is triggered if B is true, you use A || B. This means:



          • do this if A is true or B is true.






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 8 at 2:00









          Eric PostpischilEric Postpischil

          78.9k886166




          78.9k886166























              2














              In the end, you'll probably want a switch case.



              main()

              char in;
              int ans=10;
              printf ("Enter character");
              scanf ("%c",&in);
              switch(in)
              case '+':
              ans=ans+10;
              break;
              case '-':
              ans=ans-10;
              break;
              case '/':
              ans=ans/10;
              break;
              case '*':
              ans=ans*10;
              break;





              Further steps in the exercise are probably going to be to parse the input factors to the calculations as well, rather than just multiplying static ans with 10.






              share|improve this answer





























                2














                In the end, you'll probably want a switch case.



                main()

                char in;
                int ans=10;
                printf ("Enter character");
                scanf ("%c",&in);
                switch(in)
                case '+':
                ans=ans+10;
                break;
                case '-':
                ans=ans-10;
                break;
                case '/':
                ans=ans/10;
                break;
                case '*':
                ans=ans*10;
                break;





                Further steps in the exercise are probably going to be to parse the input factors to the calculations as well, rather than just multiplying static ans with 10.






                share|improve this answer



























                  2












                  2








                  2







                  In the end, you'll probably want a switch case.



                  main()

                  char in;
                  int ans=10;
                  printf ("Enter character");
                  scanf ("%c",&in);
                  switch(in)
                  case '+':
                  ans=ans+10;
                  break;
                  case '-':
                  ans=ans-10;
                  break;
                  case '/':
                  ans=ans/10;
                  break;
                  case '*':
                  ans=ans*10;
                  break;





                  Further steps in the exercise are probably going to be to parse the input factors to the calculations as well, rather than just multiplying static ans with 10.






                  share|improve this answer















                  In the end, you'll probably want a switch case.



                  main()

                  char in;
                  int ans=10;
                  printf ("Enter character");
                  scanf ("%c",&in);
                  switch(in)
                  case '+':
                  ans=ans+10;
                  break;
                  case '-':
                  ans=ans-10;
                  break;
                  case '/':
                  ans=ans/10;
                  break;
                  case '*':
                  ans=ans*10;
                  break;





                  Further steps in the exercise are probably going to be to parse the input factors to the calculations as well, rather than just multiplying static ans with 10.







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Mar 20 at 0:33

























                  answered Mar 8 at 2:03









                  visiblemanvisibleman

                  1,694820




                  1,694820



























                      draft saved

                      draft discarded
















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid


                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.

                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55055652%2fhow-to-use-more-than-1-condition-in-one-if-function%23new-answer', 'question_page');

                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme

                      Identity Server 4 is not redirecting to Angular app after login2019 Community Moderator ElectionIdentity Server 4 and dockerIdentityserver implicit flow unauthorized_clientIdentityServer Hybrid Flow - Access Token is null after user successful loginIdentity Server to MVC client : Page Redirect After loginLogin with Steam OpenId(oidc-client-js)Identity Server 4+.NET Core 2.0 + IdentityIdentityServer4 post-login redirect not working in Edge browserCall to IdentityServer4 generates System.NullReferenceException: Object reference not set to an instance of an objectIdentityServer4 without HTTPS not workingHow to get Authorization code from identity server without login form

                      2005 Ahvaz unrest Contents Background Causes Casualties Aftermath See also References Navigation menue"At Least 10 Are Killed by Bombs in Iran""Iran"Archived"Arab-Iranians in Iran to make April 15 'Day of Fury'"State of Mind, State of Order: Reactions to Ethnic Unrest in the Islamic Republic of Iran.10.1111/j.1754-9469.2008.00028.x"Iran hangs Arab separatists"Iran Overview from ArchivedConstitution of the Islamic Republic of Iran"Tehran puzzled by forged 'riots' letter""Iran and its minorities: Down in the second class""Iran: Handling Of Ahvaz Unrest Could End With Televised Confessions""Bombings Rock Iran Ahead of Election""Five die in Iran ethnic clashes""Iran: Need for restraint as anniversary of unrest in Khuzestan approaches"Archived"Iranian Sunni protesters killed in clashes with security forces"Archived