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=]”
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
add a comment |
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
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
add a comment |
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
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
c
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
add a comment |
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
add a comment |
2 Answers
2
active
oldest
votes
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.
add a comment |
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.
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
add a comment |
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.
add a comment |
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.
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.
answered Mar 8 at 2:00
Eric PostpischilEric Postpischil
78.9k886166
78.9k886166
add a comment |
add a comment |
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.
add a comment |
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.
add a comment |
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.
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.
edited Mar 20 at 0:33
answered Mar 8 at 2:03
visiblemanvisibleman
1,694820
1,694820
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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