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

Create a Code Blocks project named calculators. This program will ask for input,

ID: 3887021 • Letter: C

Question

Create a Code Blocks project named calculators. This program will ask for input, make one or more calculations, and after each calculation output the calculated value. I would suggest using doubles or floats for this program.

1. Add two numbers as follows:
Enter a number: 4
Enter another number: 16
Those two added together is 20

2. Subtract two numbers as follows:
Enter a number 44
Enter another number 17
The second number subtracted from the first number is 27

3. Multiply two numbers (similar to the first two examples)

4. Divide two numbers  (similar to the first two examples)

5. Ask for a number of gallons, then show how many quarts, pints, cups, and ounces that is.

6. Ask for a number of miles, then show how many yards, feet, and inches that is.

Explanation / Answer

# include <stdio.h>
int main() {

int option;
double number1,number2;

printf("1.Add two numbers 2.Substract two numbers 3.Multiply two numbers 4.Divide two numbers 5.Convert gallons 6.Convert miles Enter option:");
  
scanf("%d", &option);

switch(option)
{
case 1:
printf("Enter two numbers: ");
scanf("%lf %lf",&number1, &number2);
printf("%.1lf + %.1lf = %.1lf ",number1, number2, number1 + number2);
break;

case 2:
printf("Enter two numbers: ");
scanf("%lf %lf",&number1, &number2);
printf("%.1lf - %.1lf = %.1lf ",number1, number2, number1 - number2);
break;

case 3:
printf("Enter two numbers: ");
scanf("%lf %lf",&number1, &number2);
printf("%.1lf * %.1lf = %.1lf ",number1, number2, number1 * number2);
break;

case 4:
printf("Enter two numbers: ");
scanf("%lf %lf",&number1, &number2);
printf("%.1lf / %.1lf = %.1lf ",number1, number2, number1 / number2);
break;
case 5:
printf("Enter gallons: ");
scanf("%lf",&number1);
printf("%.1lf gallons = %.1f quarts ",number1,number1*4);
printf("%.1lf gallons = %.1f pints ",number1,number1*8);
printf("%.1lf gallons = %.1f cups ",number1,number1*16);
printf("%.1lf gallons = %.1f ounces ",number1,number1*128);
break;
  
case 6:
printf("Enter miles: ");
scanf("%lf",&number2);
printf("%.1lf miles = %.1f yards ",number2,number2*1760);
printf("%.1lf miles = %.1f feet ",number2,number2*5280);
printf("%.1lf miles = %.1f inches ",number2,number2*63360);
break;

// option doesn't match any case constant (+, -, *, /)
default:
printf("Error! option is not correct");
}
  
return 0;
}