Turn Switch statement into if/then and if/else statement









up vote
0
down vote

favorite












I want to make this switch statement into if/else and if/then statement.
My Switch statement is :



char option;
printf("Choose your option : ");
scanf("%c",&option);

switch(option)
case 'a':
case 'A': a = 20 + 10 ;
printf("Addition process result:%d",a);
break;
case 'b':
case 'B': a = 20 - 10 ;
printf("Subtraction process result:%d",a);
break;
case 'c':
case 'C': a = 20 * 10 ;
printf("Multiplication process result:%d",a);
break;
case 'd':
case 'D': a = 20 + 10 ;
printf("Division process result:%d",a);
break;
default:
printf("Invalid option");










share|improve this question

















  • 3




    I won't answer, because I think your code works better with a switch statement.
    – Tim Biegeleisen
    Nov 8 at 16:53






  • 3




    Make an attempt. If you can't get it working, show us what you've tried.
    – dbush
    Nov 8 at 16:56






  • 1




    There is no if/then statement in C.
    – Steve Summit
    Nov 8 at 17:16






  • 1




    Why do you want to convert to "if/then" or "if/else" statement? What do you think, such a statement looks like? Please show us an example. BTW: There is no then in C
    – Gerhardh
    Nov 8 at 17:33











  • It would improve your code more if you used toupper(option) and only use one value per case, than turning everything inside out to use "if/else"
    – Gerhardh
    Nov 8 at 17:34














up vote
0
down vote

favorite












I want to make this switch statement into if/else and if/then statement.
My Switch statement is :



char option;
printf("Choose your option : ");
scanf("%c",&option);

switch(option)
case 'a':
case 'A': a = 20 + 10 ;
printf("Addition process result:%d",a);
break;
case 'b':
case 'B': a = 20 - 10 ;
printf("Subtraction process result:%d",a);
break;
case 'c':
case 'C': a = 20 * 10 ;
printf("Multiplication process result:%d",a);
break;
case 'd':
case 'D': a = 20 + 10 ;
printf("Division process result:%d",a);
break;
default:
printf("Invalid option");










share|improve this question

















  • 3




    I won't answer, because I think your code works better with a switch statement.
    – Tim Biegeleisen
    Nov 8 at 16:53






  • 3




    Make an attempt. If you can't get it working, show us what you've tried.
    – dbush
    Nov 8 at 16:56






  • 1




    There is no if/then statement in C.
    – Steve Summit
    Nov 8 at 17:16






  • 1




    Why do you want to convert to "if/then" or "if/else" statement? What do you think, such a statement looks like? Please show us an example. BTW: There is no then in C
    – Gerhardh
    Nov 8 at 17:33











  • It would improve your code more if you used toupper(option) and only use one value per case, than turning everything inside out to use "if/else"
    – Gerhardh
    Nov 8 at 17:34












up vote
0
down vote

favorite









up vote
0
down vote

favorite











I want to make this switch statement into if/else and if/then statement.
My Switch statement is :



char option;
printf("Choose your option : ");
scanf("%c",&option);

switch(option)
case 'a':
case 'A': a = 20 + 10 ;
printf("Addition process result:%d",a);
break;
case 'b':
case 'B': a = 20 - 10 ;
printf("Subtraction process result:%d",a);
break;
case 'c':
case 'C': a = 20 * 10 ;
printf("Multiplication process result:%d",a);
break;
case 'd':
case 'D': a = 20 + 10 ;
printf("Division process result:%d",a);
break;
default:
printf("Invalid option");










share|improve this question













I want to make this switch statement into if/else and if/then statement.
My Switch statement is :



char option;
printf("Choose your option : ");
scanf("%c",&option);

switch(option)
case 'a':
case 'A': a = 20 + 10 ;
printf("Addition process result:%d",a);
break;
case 'b':
case 'B': a = 20 - 10 ;
printf("Subtraction process result:%d",a);
break;
case 'c':
case 'C': a = 20 * 10 ;
printf("Multiplication process result:%d",a);
break;
case 'd':
case 'D': a = 20 + 10 ;
printf("Division process result:%d",a);
break;
default:
printf("Invalid option");







c if-statement if-this-then-that






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 8 at 16:50









singlepiece000

125




125







  • 3




    I won't answer, because I think your code works better with a switch statement.
    – Tim Biegeleisen
    Nov 8 at 16:53






  • 3




    Make an attempt. If you can't get it working, show us what you've tried.
    – dbush
    Nov 8 at 16:56






  • 1




    There is no if/then statement in C.
    – Steve Summit
    Nov 8 at 17:16






  • 1




    Why do you want to convert to "if/then" or "if/else" statement? What do you think, such a statement looks like? Please show us an example. BTW: There is no then in C
    – Gerhardh
    Nov 8 at 17:33











  • It would improve your code more if you used toupper(option) and only use one value per case, than turning everything inside out to use "if/else"
    – Gerhardh
    Nov 8 at 17:34












  • 3




    I won't answer, because I think your code works better with a switch statement.
    – Tim Biegeleisen
    Nov 8 at 16:53






  • 3




    Make an attempt. If you can't get it working, show us what you've tried.
    – dbush
    Nov 8 at 16:56






  • 1




    There is no if/then statement in C.
    – Steve Summit
    Nov 8 at 17:16






  • 1




    Why do you want to convert to "if/then" or "if/else" statement? What do you think, such a statement looks like? Please show us an example. BTW: There is no then in C
    – Gerhardh
    Nov 8 at 17:33











  • It would improve your code more if you used toupper(option) and only use one value per case, than turning everything inside out to use "if/else"
    – Gerhardh
    Nov 8 at 17:34







3




3




I won't answer, because I think your code works better with a switch statement.
– Tim Biegeleisen
Nov 8 at 16:53




I won't answer, because I think your code works better with a switch statement.
– Tim Biegeleisen
Nov 8 at 16:53




3




3




Make an attempt. If you can't get it working, show us what you've tried.
– dbush
Nov 8 at 16:56




Make an attempt. If you can't get it working, show us what you've tried.
– dbush
Nov 8 at 16:56




1




1




There is no if/then statement in C.
– Steve Summit
Nov 8 at 17:16




There is no if/then statement in C.
– Steve Summit
Nov 8 at 17:16




1




1




Why do you want to convert to "if/then" or "if/else" statement? What do you think, such a statement looks like? Please show us an example. BTW: There is no then in C
– Gerhardh
Nov 8 at 17:33





Why do you want to convert to "if/then" or "if/else" statement? What do you think, such a statement looks like? Please show us an example. BTW: There is no then in C
– Gerhardh
Nov 8 at 17:33













It would improve your code more if you used toupper(option) and only use one value per case, than turning everything inside out to use "if/else"
– Gerhardh
Nov 8 at 17:34




It would improve your code more if you used toupper(option) and only use one value per case, than turning everything inside out to use "if/else"
– Gerhardh
Nov 8 at 17:34












2 Answers
2






active

oldest

votes

















up vote
1
down vote













like this:



#include <stdio.h>

int main()





share|improve this answer




















  • how to convert in if/then statement ?
    – singlepiece000
    Nov 8 at 17:03










  • @singlepiece000 What is if/then statement?
    – Yunbin Liu
    Nov 8 at 17:08






  • 1




    @YunbinLiu He doesn't know. He copied those words -- without understanding them, and perhaps inaccurately -- from his homework assignment, which you've just tried to do for him.
    – Steve Summit
    Nov 8 at 17:12


















up vote
1
down vote













You just do:



if(option == 'a' || option == 'A') 
// do whatever

else if (option == 'b' || option == 'B')
// do whatever



... the other else if's



then for the "invalid option", you have just an else . If the first if or any of the subsequent else if's evaluate true, then all the others will be skipped.






share|improve this answer






















  • ok, I figure out if/else. But how to turn into if/then statement?
    – singlepiece000
    Nov 8 at 17:01











  • @singlepiece000 What exactly does that mean? If you made a change to your code, compile it and run it to test it.
    – dbush
    Nov 8 at 17:02










  • @dbush What it means is that those words "I want to make this switch statement into if/else and if/then statement" are the OP's uncomprehending paraphrase of a homework assignment. Perhaps the assignment was misleading, or perhaps something got lost in translation.
    – Steve Summit
    Nov 8 at 17:15










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',
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%2f53212453%2fturn-switch-statement-into-if-then-and-if-else-statement%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








up vote
1
down vote













like this:



#include <stdio.h>

int main()





share|improve this answer




















  • how to convert in if/then statement ?
    – singlepiece000
    Nov 8 at 17:03










  • @singlepiece000 What is if/then statement?
    – Yunbin Liu
    Nov 8 at 17:08






  • 1




    @YunbinLiu He doesn't know. He copied those words -- without understanding them, and perhaps inaccurately -- from his homework assignment, which you've just tried to do for him.
    – Steve Summit
    Nov 8 at 17:12















up vote
1
down vote













like this:



#include <stdio.h>

int main()





share|improve this answer




















  • how to convert in if/then statement ?
    – singlepiece000
    Nov 8 at 17:03










  • @singlepiece000 What is if/then statement?
    – Yunbin Liu
    Nov 8 at 17:08






  • 1




    @YunbinLiu He doesn't know. He copied those words -- without understanding them, and perhaps inaccurately -- from his homework assignment, which you've just tried to do for him.
    – Steve Summit
    Nov 8 at 17:12













up vote
1
down vote










up vote
1
down vote









like this:



#include <stdio.h>

int main()





share|improve this answer












like this:



#include <stdio.h>

int main()






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 8 at 17:00









Yunbin Liu

930210




930210











  • how to convert in if/then statement ?
    – singlepiece000
    Nov 8 at 17:03










  • @singlepiece000 What is if/then statement?
    – Yunbin Liu
    Nov 8 at 17:08






  • 1




    @YunbinLiu He doesn't know. He copied those words -- without understanding them, and perhaps inaccurately -- from his homework assignment, which you've just tried to do for him.
    – Steve Summit
    Nov 8 at 17:12

















  • how to convert in if/then statement ?
    – singlepiece000
    Nov 8 at 17:03










  • @singlepiece000 What is if/then statement?
    – Yunbin Liu
    Nov 8 at 17:08






  • 1




    @YunbinLiu He doesn't know. He copied those words -- without understanding them, and perhaps inaccurately -- from his homework assignment, which you've just tried to do for him.
    – Steve Summit
    Nov 8 at 17:12
















how to convert in if/then statement ?
– singlepiece000
Nov 8 at 17:03




how to convert in if/then statement ?
– singlepiece000
Nov 8 at 17:03












@singlepiece000 What is if/then statement?
– Yunbin Liu
Nov 8 at 17:08




@singlepiece000 What is if/then statement?
– Yunbin Liu
Nov 8 at 17:08




1




1




@YunbinLiu He doesn't know. He copied those words -- without understanding them, and perhaps inaccurately -- from his homework assignment, which you've just tried to do for him.
– Steve Summit
Nov 8 at 17:12





@YunbinLiu He doesn't know. He copied those words -- without understanding them, and perhaps inaccurately -- from his homework assignment, which you've just tried to do for him.
– Steve Summit
Nov 8 at 17:12













up vote
1
down vote













You just do:



if(option == 'a' || option == 'A') 
// do whatever

else if (option == 'b' || option == 'B')
// do whatever



... the other else if's



then for the "invalid option", you have just an else . If the first if or any of the subsequent else if's evaluate true, then all the others will be skipped.






share|improve this answer






















  • ok, I figure out if/else. But how to turn into if/then statement?
    – singlepiece000
    Nov 8 at 17:01











  • @singlepiece000 What exactly does that mean? If you made a change to your code, compile it and run it to test it.
    – dbush
    Nov 8 at 17:02










  • @dbush What it means is that those words "I want to make this switch statement into if/else and if/then statement" are the OP's uncomprehending paraphrase of a homework assignment. Perhaps the assignment was misleading, or perhaps something got lost in translation.
    – Steve Summit
    Nov 8 at 17:15














up vote
1
down vote













You just do:



if(option == 'a' || option == 'A') 
// do whatever

else if (option == 'b' || option == 'B')
// do whatever



... the other else if's



then for the "invalid option", you have just an else . If the first if or any of the subsequent else if's evaluate true, then all the others will be skipped.






share|improve this answer






















  • ok, I figure out if/else. But how to turn into if/then statement?
    – singlepiece000
    Nov 8 at 17:01











  • @singlepiece000 What exactly does that mean? If you made a change to your code, compile it and run it to test it.
    – dbush
    Nov 8 at 17:02










  • @dbush What it means is that those words "I want to make this switch statement into if/else and if/then statement" are the OP's uncomprehending paraphrase of a homework assignment. Perhaps the assignment was misleading, or perhaps something got lost in translation.
    – Steve Summit
    Nov 8 at 17:15












up vote
1
down vote










up vote
1
down vote









You just do:



if(option == 'a' || option == 'A') 
// do whatever

else if (option == 'b' || option == 'B')
// do whatever



... the other else if's



then for the "invalid option", you have just an else . If the first if or any of the subsequent else if's evaluate true, then all the others will be skipped.






share|improve this answer














You just do:



if(option == 'a' || option == 'A') 
// do whatever

else if (option == 'b' || option == 'B')
// do whatever



... the other else if's



then for the "invalid option", you have just an else . If the first if or any of the subsequent else if's evaluate true, then all the others will be skipped.







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 8 at 17:15

























answered Nov 8 at 16:56









Austin Stephens

41149




41149











  • ok, I figure out if/else. But how to turn into if/then statement?
    – singlepiece000
    Nov 8 at 17:01











  • @singlepiece000 What exactly does that mean? If you made a change to your code, compile it and run it to test it.
    – dbush
    Nov 8 at 17:02










  • @dbush What it means is that those words "I want to make this switch statement into if/else and if/then statement" are the OP's uncomprehending paraphrase of a homework assignment. Perhaps the assignment was misleading, or perhaps something got lost in translation.
    – Steve Summit
    Nov 8 at 17:15
















  • ok, I figure out if/else. But how to turn into if/then statement?
    – singlepiece000
    Nov 8 at 17:01











  • @singlepiece000 What exactly does that mean? If you made a change to your code, compile it and run it to test it.
    – dbush
    Nov 8 at 17:02










  • @dbush What it means is that those words "I want to make this switch statement into if/else and if/then statement" are the OP's uncomprehending paraphrase of a homework assignment. Perhaps the assignment was misleading, or perhaps something got lost in translation.
    – Steve Summit
    Nov 8 at 17:15















ok, I figure out if/else. But how to turn into if/then statement?
– singlepiece000
Nov 8 at 17:01





ok, I figure out if/else. But how to turn into if/then statement?
– singlepiece000
Nov 8 at 17:01













@singlepiece000 What exactly does that mean? If you made a change to your code, compile it and run it to test it.
– dbush
Nov 8 at 17:02




@singlepiece000 What exactly does that mean? If you made a change to your code, compile it and run it to test it.
– dbush
Nov 8 at 17:02












@dbush What it means is that those words "I want to make this switch statement into if/else and if/then statement" are the OP's uncomprehending paraphrase of a homework assignment. Perhaps the assignment was misleading, or perhaps something got lost in translation.
– Steve Summit
Nov 8 at 17:15




@dbush What it means is that those words "I want to make this switch statement into if/else and if/then statement" are the OP's uncomprehending paraphrase of a homework assignment. Perhaps the assignment was misleading, or perhaps something got lost in translation.
– Steve Summit
Nov 8 at 17:15

















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53212453%2fturn-switch-statement-into-if-then-and-if-else-statement%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

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

How do I collapse sections of code in Visual Studio Code for Windows?

ャフサォクコ ケウ,コ,ワ メ,ロスョノ゙,クネ,フムカヤヲニ,エコ゚ツ ウイオン゙ケワサネォキモュキォウイノンコチ゚メヌナイゥフュ,カヒウネェ ネ,ホノケ,ムュキ ッボーミュハ,チ ツス ィ メウイマヤ,゙ウチ ヅ ロ,ォジヌェ ャヌット ェ,マャ,チナエヒネソキツテ トホヲヲミーァ