can you place a if/else statement in a switch case?
ex:
case 4:
answer=f+b
cout<<sum<<answer<<endl;
break;
if (f > 5)
else .......
can i do this??
can you place a if/else statement in a switch case?
ex:
case 4:
answer=f+b
cout<<sum<<answer<<endl;
break;
if (f > 5)
else .......
can i do this??
Yes, try it. You can call functions, exit the program, write as much code as you want in a case block. Anything after the break and before the next case is ignored, tho.
C programming resources:
GNU C Function and Macro Index -- glibc reference manual
The C Book -- nice online learner guide
Current ISO draft standard
CCAN -- new CPAN like open source library repository
3 (different) GNU debugger tutorials: #1 -- #2 -- #3
cpwiki -- our wiki on sourceforge
No, but you could do
orCode:switch(f) { case 4: break; default: if(f > 5) // something else // else break; }
orCode:if(f > 5) // something else { switch(f) { case 4: break; } }
Code:if(f == 4) // something else if(f > 5) // else if else // else
Warning: Have doubt in anything I post.
GCC 4.5, Boost 1.40, Code::Blocks 8.02, Ubuntu 9.10 010001000110000101100101
Last edited by Dae; 02-27-2010 at 08:46 PM.
Warning: Have doubt in anything I post.
GCC 4.5, Boost 1.40, Code::Blocks 8.02, Ubuntu 9.10 010001000110000101100101
so how could i write a statement that :
asks for a letter ( i used D for division) when entered the program is going to ask the user for two numbers,but i need to divide the larger number by the smaller number.
and i also need :
when s ( subtraction is wanted) the program will calculate difference, subtracting the second number from the first number, but only when the first number is larger than the second number. and the program should swap both numbers before calculating the number
its confusing me alot!!!
i tried some stuff but it gave me errors
ps: also when i am only using ( a-addition,s-subtraction,m-multiplication,d-division) but when i enter the letter J or any other it still asks for two number..i already placed the default in the switch case but it still asks ...HELP!!! lol