Note that there are some explanatory texts on larger screens.

plurals
  1. POC Primer Plus Programming Exercise Question
    primarykey
    data
    text
    <p>I'm working through 'C Primer Plus', was just going through the programming exercises and I've hit a brick wall on the last one on the fifth chapter (Operators, Expressions and Statements).</p> <p>The exercise is:</p> <p>Write a program that requests the user to enter a Fahrenheit temperature. The program should read the temperature as a type double number and pass it as an argument to a user-supplied function called Temperatures(). This function should calculate the Celsius equivalent and the Kelvin equivalent and display all three temperatures with a precision of two places to the right of the decimal. It should identify each value with the temperature scale it represents. Here is the formula for converting Fahrenheit to Celsius:</p> <p>Celsius = 1.8 * Fahrenheit + 32.0</p> <p>The Kelvin scale, commonly used in science, is a scale in which 0 represents absolute zero, the lower limit to possible temperatures. Here is the formula for converting Celsius to Kelvin:</p> <p>Kelvin = Celsius + 273.16</p> <p>The Temperatures() function should use const to create symbolic representations of the three constants that appear in the conversions. The main() function should use a loop to allow the user to enter temperatures repeatedly, stopping when a q or other nonnumeric value is entered.</p> <p>My code is:</p> <pre><code>#include &lt;stdio.h&gt; void Temperatures(double); int main(void) { double farh; printf("Enter a fahrenheit temperature: "); scanf("%f", &amp;farh); printf("\n"); Temperatures(farh); return 0; } void Temperatures(double f) { float c; float k; c = 1.8 * f + 32; k = c + 273.16; printf("Fahrenheit Celcius Kelvin\n"); printf("%.2f %.2f %.2f\n", f, c, k); } </code></pre> <p>Where have I gone wrong? :o Just get nonsense.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload