Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Must Be Written In Basic C Scenario: Santa got the flu on Christmas and will not

ID: 2267917 • Letter: M

Question

Must Be Written In Basic C

Scenario: Santa got the flu on Christmas and will not be able to pilot his sleigh to deliver toys.

In order to be able to drop the toys at the targeted chimneys from high altitude, a targeting mechanism needed to be acquired. The matter was “discussed” with a guard at the Smithsonian and a bombsight was “borrowed” to be fitted on the sleigh.

Program 2:

In order not to be seen, you have to fly between 5000 and 10000 feet at all times. A vintage Norton bombsight was “borrowed” from a WWII B17 flying fortress and installed on Santa’s sleigh. The bombsight requires adjustments for elevation at increments of 1000 feet.

Write a program that asks for and stores the elevation of the sleigh on the path to each toy drop that will output the added calibration alignment of the bombsight according to the following table.

Altitude Range in feet

Calibration Adjustment

5001-6000

20

6001-7000

33

7001-8000

46

8001-9000

52

9001-10000

57

The toys are packaged in boxes labeled a, b, c, or d.

Ask the user for the box type and store it in the appropriate type variable.

Adjust the bombsight calibration by decreasing the output calibration value by:

Decrease calibration by

Box type

5%

a

7%

b

8%

c

10%

d

Sample input/output:

Please enter the altitude in feet: 7632

Please enter the box type: d

The bombsight calibration should be adjusted to: 41.40

Needs Help Correcting this, I can not get it to work.

#include <stdio.h>

int main()

{

int altitude = 0;

int ar[4] = {5,7,8,10}; //initialization of box type calibration decrease percent

double ca = 0.0; //ca is the calibration adjustment

char box_Type = 'a';

printf("Please enter the altitude in feet : ");

scanf(" %d",&altitude);

printf("Please enter the box type : ");

scanf(" %c",&box_Type);

if(5001 <= altitude && altitude <= 6000)

{

ca = 20.0;

}

else if(6001 <= altitude && altitude <= 7000)

{

ca = 33.0;

}

else if(7001 <= altitude && altitude <= 8000)

{

ca = 46.0;

}

else if(8001 <= altitude && altitude <= 9000)

{

ca = 52.0;

}

else if(9001 <= altitude && altitude <= 10000)

{

ca = 57.0;

}

else

{

printf("Please enter a valid range of altitude (5001 - 10000) ");

}

for(int i = 0;i<4;i++)

{

if(box_Type == 'a'+i)

{

ca = (ca - (ca*ar[i]/100));

}

}

if(5001 <= altitude && altitude <= 10000 && 'a' <= box_Type && box_Type <= 'd')

{

printf("The bombsight calibration should be adjusted to : %0.2lf ",ca);

}

if(box_Type > 'd' || box_Type < 'a')

{

printf("Please enter alphabet a or b or c or d ");

}

return(0);

}

Altitude Range in feet

Calibration Adjustment

5001-6000

20

6001-7000

33

7001-8000

46

8001-9000

52

9001-10000

57

Explanation / Answer

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <assert.h>

int main()
{
   int altitude = 0;
   int ar[4] = {5,7,8,10}; //initialization of box type calibration decrease percent
   double ca = 0.0; //ca is the calibration adjustment
   char box_Type;
   while (1) {
   printf("Please enter the altitude in feet :: ");
   scanf(" %d",&altitude);
   if((altitude <= 5000 ) || (altitude >= 10000)) {
   printf("Please enter a valid range of altitude (5001 - 10000) ");
   continue;
   } else {
   break;
   }
   }

   while (1) {
   printf("Please enter the box type :: ");
   scanf(" %c",&box_Type);
   if((box_Type > 'd') || (box_Type < 'a')) {
   printf("Please enter alphabet a or b or c or d ");
   continue;
   } else {
   break;
   }
   }
  

   if(5001 <= altitude && altitude <= 6000) {
   ca = 20.0;
   }
   else if(6001 <= altitude && altitude <= 7000) {
   ca = 33.0;
   }
   else if(7001 <= altitude && altitude <= 8000) {
   ca = 46.0;
   }
   else if(8001 <= altitude && altitude <= 9000) {
   ca = 52.0;
   }
   else if(9001 <= altitude && altitude <= 10000) {
   ca = 57.0;
   }

   if (box_Type == 'a') {
   ca = (ca - (ca*ar[0]/100));
   }
   else if (box_Type == 'b') {
   ca = (ca - (ca*ar[1]/100));
   }
   else if (box_Type == 'c') {
   ca = (ca - (ca*ar[2]/100));
   }
   else if (box_Type == 'd') {
   ca = (ca - (ca*ar[3]/100));
   }

   printf("The bombsight calibration should be adjusted to :: %0.2lf ",ca);
   return(0);
}