I'm trying to create a if else statement within another if else statement or can i create if else statement within a switch statement? advice........
Here's some information on control structures from the tutorial.
http://www.cplusplus.com/doc/tutorial/control/
Note that these are all statements so they may be nested:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
|
if( condition1 )
{
if( condition2 )
{
// condition1 && condition2
}
else
{
// condition1 && !condition2
}
}
else
{
if( condition2 )
{
// !condition1 && condition2
}
else
{
// !condition1 && !condition2
}
}
|
The conditions can be combined as well, for example:
1 2 3
|
if( condition1 && condition2 ) {
// both conditions are true
}
|
Last edited on
if i do it this can it be executed?
if ((Ward == 'A')&& (Type == "Acute ward") || (Ward == 'a')&& (Type == "acute ward") )
{
Ward_fees = 230;
}
else if ((Ward == 'A')&& (Type == "Intensive care unit") || (Ward == 'a')&& (Type == "intensive care unit"))
{
Ward_fees = 500;
}
else if ((Ward == 'A')&& (Type == "Consultation") || (Ward == 'a')&& (Type == "consultation"))
{
Ward_fees = 50;
}
else if ((Ward == 'B')&& (Type == "Acute ward") || (Ward == 'b')&& (Type == "acute ward"))
{
Ward_fees = 150;
}
else if ((Ward == 'B')&& (Type == "Intensive care unit") || (Ward == 'b')&& (Type == "intensive care unit"))
{
Ward_fees = 300;
}
else if((Ward == 'B')&& (Type == "Consultation") || (Ward == 'b')&& (Type == "consultation"))
{
Ward_fees = 40;
}
else if ((Ward == 'C')&& (Type == "Acute ward") || (Ward == 'c')&& (Type == "acute ward"))
{
Ward_fees = 75;
}
else if ((Ward == 'C')&& (Type == "Intensive care unit") || (Ward == 'c')&& (Type == "intensive care unit"))
{
Ward_fees = 150;
}
else if ((Ward == 'C')&& (Type == "Consultation") || (Ward == 'c')&& (Type == "consultation"))
{
Ward_fees = 25;
}
else
{
Ward_fees = 0;
}
Syntax:
if (****) {
**
**
}
else if (***){
**
**
}
one open ( one closed ); not five or six
If i want to do it by using switch statement instead of if else, can it be done ?
You can only switch on integral types, so you could do part of it.