November 2013
Beginner
325 pages
9h 47m
English
Many functions return a value when they complete execution. You know what type of data a function will return by the type that precedes the function name. (If a function does not return anything, its return type is void.)
Create a new C Command Line Tool named Degrees. In main.c, add a function before main() that converts a temperature from Celsius to Fahrenheit. Then update main() to call the new function.
#include <stdio.h>
float fahrenheitFromCelsius(float cel)
{
float fahr = cel * 1.8 + 32.0;
printf("%f Celsius is %f Fahrenheit\n", cel, fahr);
return fahr;
}
int main(int argc, const char * argv[])
{
float freezeInC = 0; float freezeInF = fahrenheitFromCelsius(freezeInC); printf("Water freezes at %f degrees Fahrenheit.\n", ...Read now
Unlock full access