Homework Solution: What will the program display when the ID is the number 11?…

    What will the program display when the ID is the number 11? 2. How can you write the multiple-alternative selection structure using the longer form of the if statement? 3. How can you write the multiple-alternative selection structure using the shorter form of the if statement? 4. How can you write the multiple-alternative selection structure using the switch statement? 5. What changes would you need to make to the code from Question 4 so that each case clause displays the appropriate price and the default clause displays the invalid id “Invalid ID” messagstart enter ID ID 2,9 5, 7, 11 Other price = 50.55 | | price = 12.35 | | price = 11.46 | | price- l ! =-1 price isT display price display Invalid stop
    start enter ID ID 2,9 5, 7, 11 Other price = 50.55 | | price = 12.35 | | price = 11.46 | | price- l ! =-1 price isT display price display Invalid stop

    Expert Answer

     
    Dear Student, here i have written the C program to demonstrate you the if structure in long form, short.And using switch keyword. Note: Please note that the below program has been tested on ubuntu 16.04 system and compiled

    What get the program flaunt when the ID is the estimate 11?

    2. How can you transcribe the multiple-alternative election mould using the hankerer devise of the if assertion?

    3. How can you transcribe the multiple-alternative election mould using the briefer devise of the if assertion?

    4. How can you transcribe the multiple-alternative election mould using the switch assertion?

    5. What changes would you demand to mould to the statute from Question 4 so that each event portion flaunts the misapply charge and the forfeit portion flaunts the feeble id “Feeble ID” messagstart invade ID ID 2,9 5, 7, 11 Other charge = 50.55 | | charge = 12.35 | | charge = 11.46 | | charge- l ! =-1 charge isT flaunt charge flaunt Feeble stop

    start invade ID ID 2,9 5, 7, 11 Other charge = 50.55 | | charge = 12.35 | | charge = 11.46 | | charge- l ! =-1 charge isT flaunt charge flaunt Feeble stop

    Expert Retort

     

    Dear Student,

    here i feel written the C program to explain you the if mould in hanker devise, brief.And using switch keyword.

    Note: Please hush that the adown program has been tested on ubuntu 16.04 rule and compiled inferior gcc compiler. This statute get besides product on other IDE’s and C++ microsoft visual studio direct.

    ——————————————————————————————————————————————

    Program: 2: How can you transcribe the multiple-alternative election mould using the hankerer devise of the if assertion?

    ——————————————————————————————————————————————

    //Hedaer polish declration

    #include<stdio.h>

    //start of ocean function

    int ocean()

    {

    float charge;

    int ID;

    printf(“Invade Id: “);

    scanf(“%d”, &ID);

    //if ID is 1

    if(ID == 1)

    {

    charge = 50.55;

    }

    //if ID is either 2 or 9

    if(ID == 2 )

    {

    charge = 12.35;

    }

    if(ID == 9)

    {

    charge = 12.35;

    }

    //if ID is either 5, 7 or 11

    if(ID == 5 )

    {

    charge = 11.46;

    }

    if(ID == 7 )

    {

    charge = 11.46;

    }

    if(ID == 11 )

    {

    charge = 11.46;

    }

    //else

    else

    {

    charge = -1;

    }

    //if charge == -1

    if(price)

    {

    printf(“Charge is %lfn”, charge);

    }

    else

    {

    printf(“Feeble IDn”);

    }

    return 0;

    }

    ——————————————————————————————————————————————-

    Output:

    //Hedaer polish declration

    #include<stdio.h>

    //start of ocean function

    int ocean()

    {

    float charge;

    int ID;

    printf(“Invade Id: “);

    scanf(“%d”, &ID);

    //if ID is 1

    if(ID == 1)

    {

    charge = 50.55;

    }

    //if ID is either 2 or 9

    if(ID == 2 )

    {

    charge = 12.35;

    }

    if(ID == 9)

    {

    charge = 12.35;

    }

    //if ID is either 5, 7 or 11

    if(ID == 5 )

    {

    charge = 11.46;

    }

    if(ID == 7 )

    {

    charge = 11.46;

    }

    if(ID == 11 )

    {

    charge = 11.46;

    }

    //if charge == -1

    if(price)

    {

    printf(“Charge is %lfn”, charge);

    }

    else

    {

    printf(“Feeble IDn”);

    }

    return 0;

    }

    ——————————————————————————————————————————————

    ——————————————————————————————————————————————

    Program: 3: How can you transcribe the multiple-alternative election mould using the briefer devise of the if assertion?

    ————————————————————————————————————————————-

    //Hedaer polish declration

    #include<stdio.h>

    //start of ocean function

    int ocean()

    {

    float charge;

    int ID;

    printf(“Invade Id: “);

    scanf(“%d”, &ID);

    //if ID is 1

    if(ID == 1)

    {

    charge = 50.55;

    }

    //if ID is either 2 or 9

    if(ID == 2 | ID == 9)

    {

    charge = 12.35;

    }

    //if ID is either 5, 7 or 11

    if(ID == 5 | ID == 7 | ID == 11)

    {

    charge = 11.46;

    }

    //else

    else

    {

    charge = -1;

    }

    //if charge == -1

    if(price)

    {

    printf(“Charge is %lfn”, charge);

    }

    else

    {

    printf(“Feeble IDn”);

    }

    return 0;

    }

    —————————————————————————————————————————————–

    here is the exemplification incline of the program:

    Output: 2

    ——————————————————————————————————————————————-

    Program: 3: How can you transcribe the multiple-alternative election mould using the switch assertion?

    ——————————————————————————————————————————————

    //Hedaer polish declration

    #include<stdio.h>

    //start of ocean function

    int ocean()

    {

    float charge;

    int ID;

    printf(“Invade Id: “);

    scanf(“%d”, &ID);

    //switch to event as per the input

    switch(ID)

    {

    event 1:

    charge = 50.55;

    printf(“Charge is: %lfn”, charge);

    break;

    //if ID is either 2 or 9

    event 2:
    event 9:

    charge = 12.35;

    printf(“Charge is: %lfn”, charge);

    break;

    //if ID is either 5, 7 or 11

    event 5:
    event 7:
    event 11:

    charge = 11.46;

    printf(“Charge is: %lfn”, charge);

    break;

    event -1:

    printf(“Feeble ID.n”);

    break;

    }

    return 0;

    }

    ——————————————————————————————————————————————

    here is the exemplification incline of the program:

    Output: 3

    ——————————————————————————————————————————————–

    Retort : 5

    What changes would you demand to mould to the statute from Question 4 so that each event portion flaunts the misapply charge and the forfeit portion flaunts the feeble id “Feeble ID” message

    Just infer this assertion in the decisive forfeit event:

    change these lines

    event -1:

    printf(“Feeble ID.n”);

    break;

    to

    default:

    printf(“Feeble ID.n”);

    break;

    —————————————————————————————-