Purpose:

Part 1: To write simple assignment statement. To declare variables. To code well-known formula for converting temperature.

Part 2: To demonstrate implicit and explicit type conversions.

NOTE: Advanced students: Do NOT write or use a function.

*** The student will be responsible for looking up the formula AND correctly coding the formula as an expression statement in the program. ***

[Hint: Use copy and paste and just change the value (number) for Fahrenheit with an assignment statement.]

Write a program which will print -10, 0, 10, 20, 30 Fahrenheit and use the formula to convert the values to centigrade:

1.Creates identifiers (variables) called centigrade and Fahrenheit.

2.Assigns the values of -10, 0, 10, 20, 30 to the variable Fahrenheit.

3.Uses an expression to find the equivalent value for that temperature in centigrade.

4.Use a table and prints the Fahrenheit followed by the degrees centigrade.

The output of the program will look like this:

99 celcius Firstname LastName
Fahrenheit centigrade
-5 -20.5556
15 -9.444444

Notes: CHECK your answers for being correct!

To you may type extra spaces or use a tab character: t

// Example of a tab
printf("Left t Rightn");
// ^ tab will be more than one space

Part 2: Given the following code.

Part A. Write the combinations of the division of two numbers. Check your answers with a calculator.

Part B. When the answer is wrong, use Explicit cast (page 118) to fix the wrong answers.

// declare variables
int iNum1; // an integer number
int iNum2; // a second integer number
int iAnswer; // answer as integer
float fNum1; // a real number
float fNum2; // a second real number
float fAnswer; // answer as a real number

// Initialize the variables
iNum1 = 3;
iNum2 = 5;

fNum1 = 4.2;
fNum2 = 7.6;


// A. Write assignment statements for all of the combinations
// of dividing the numbers and assigning to the answers
// to either an integer answer or a float answer
// print the results

// *************************************************
// Combination 1: integer = integer / integer

// student writes expression statement below this line:

printf("1. Integer %i is the answer when dividing Integer %i by Integer %inn", iAnswer, iNum1, iNum2);
// *************************************************


// *************************************************
// Combination 2: float = integer / integer

printf("2. Real %f is the answer when dividing Integer %i by Integer %inn", fAnswer, iNum1, iNum2);
// *************************************************


// *************************************************
// Combination 3: integer = float / integer

printf("3. Integer %i is the answer when dividing float %f by Integer %inn", iAnswer, fNum1, iNum2);
// *************************************************


// *************************************************
// Combination 4: float = float / integer
// Student writes both the expression statement and the
// print statement below this line:


// *************************************************


// *************************************************
// Combination 5: integer = float / float



// *************************************************


// *************************************************
// Combination 6: float = float / float



// *************************************************

// Using a calculator, check your answers.
// For any answer that is wrong, fix the assignment statement
// by using Explicit cast

// B. Fix of assignment statements
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.