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

C programming language text: computer science a structured programming approach

ID: 3844939 • Letter: C

Question

C programming language

text: computer science a structured programming approach using C, third edition

ch: 1-3

Problem 1: Given the temperature in degrees Fahrenheit and the desired number of decimal places in the output convert and display the temperature in the Celsius, Kelvin, Delisle, Newton, and Romer units.

• https://en.wikipedia.org/wiki/Conversion_of_units_of_temperature#Fahrenheit
• The data types for ALL variables and values in your program must be double if there is any chance of replicating our results exactly as seen below.

Example Execution #1:

Problem 2: Modify the assignment such that the user can indicate to which temperature unit the Fahrenheit value will be converted. The use of selection, including logical and relational operators, is prohibited.

Example Execution #1:

Explanation / Answer

Here is the code for the question.

Code for problem 1:

#include <stdio.h>
int main()
{
double fahrenheit;
double celsius, kelvin, delisle, newton, romer;
int deci;

printf(" Enter the temperature in degrees Fahrenheit: ");
scanf("%lf",&fahrenheit);
printf(" Enter the desired number of decimal places: ");
scanf("%d",&deci);

celsius = (fahrenheit - 32) * 5/ 9;
kelvin = (fahrenheit + 459.67) * 5 / 9;
delisle = (212 - fahrenheit ) * 5 / 6;
newton = (fahrenheit - 32) * 11 / 60;
romer = (fahrenheit - 32) * 7 / 24 + 7.5;

/*use * in format specifier to pick the number of decimal places from arugment*/
printf(" Temperature Fahrenheit : %.*f",deci,fahrenheit);
printf(" Converted Temperature Values");
printf(" -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=");
printf(" Celsius: %.*f",deci,celsius);
printf(" Kelvin: %.*f",deci,kelvin);
printf(" Delisle: %.*f",deci, delisle);
printf(" Newton: %.*f",deci, newton);
printf(" Romer: %.*f",deci, romer);
}

output

Enter the temperature in degrees Fahrenheit: 32

Enter the desired number of decimal places: 4

Temperature Fahrenheit : 32.0000

Converted Temperature Values
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Celsius: 0.0000
Kelvin: 273.1500
Delisle: 150.0000
Newton: 0.0000
Romer: 7.5000

code for problem 2:

#include <stdio.h>
int main()
{
double fahrenheit, converted;

int deci, option;

printf(" Temperture Conversion Options");
printf(" 1. to Celsius");
printf(" 2. to Kelvin");
printf(" 3. to Delisle");
printf(" 4. to Newton");
printf(" 5. to Romer");
printf(" Enter desired conversion option: ");
scanf("%d",&option);
printf(" Enter the temperature in degrees Fahrenheit: ");
scanf("%lf",&fahrenheit);
printf(" Enter the desired number of decimal places: ");
scanf("%d",&deci);
  
switch(option)
{
case 1: converted = (fahrenheit - 32) * 5/ 9;
break;
case 2: converted = (fahrenheit + 459.67) * 5 / 9;
break;
case 3: converted = (212 - fahrenheit ) * 5 / 6;
break;
case 4: converted = (fahrenheit - 32) * 11 / 60;
break;
case 5: converted = (fahrenheit - 32) * 7 / 24 + 7.5;
break;
default: converted = fahrenheit; // do no conversion for invalid choice

}

printf(" Option Selected: %d",option);
printf(" -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=");
printf(" Fahrenheit: %10.*f",deci,fahrenheit);
printf(" Conversion: %10.*f",deci,converted);
printf(" -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=");


}

output

Temperture Conversion Options
1. to Celsius
2. to Kelvin
3. to Delisle
4. to Newton
5. to Romer

Enter desired conversion option: 1

Enter the temperature in degrees Fahrenheit: 13

Enter the desired number of decimal places: 3

Option Selected: 1
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Fahrenheit: 13.000
Conversion: -10.556
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=