Tuesday 15 May 2012

Celcius to fahrenheit with pointers in C -



Celcius to fahrenheit with pointers in C -

so learned pointers , how create programs separate functions in c. made fahrenheit celcius programme compiler gives me error: "invalid utilize of void expression" in printf's.

i know it's function fahrenheit_temperature. don't see how prepare it? i've tried alter function double it's not working. ideas? thanks.

my code:

#include <stdio.h> void fahrenheit_temperature(double celcius_temp, double *fahrenheit_temp){ *fahrenheit_temp = (9.0 / 5.0) * celcius_temp + 32.0; } int main(void){ double fahrenheit_temp; printf("freezing point: %6.2f f.\n", fahrenheit_temperature(0.0, &fahrenheit_temp)); printf("boiling point: %6.2f f.\n", fahrenheit_temperature(100.0, &fahrenheit_temp)); homecoming 0; }

new code:

#include <stdio.h> void fahrenheit_temperature(double celcius_temp, double *fahrenheit_temp){ *fahrenheit_temp = (9.0 / 5.0) * celcius_temp + 32.0; } int main(void){ double fahrenheit_temp, celcius_temp; printf("enter degrees celcius: "); scanf("%lf", &celcius_temp); fahrenheit_temperature(celcius_temp, &fahrenheit_temp); printf("the converted temperature is: %f\n", fahrenheit_temp); homecoming 0; }

you have variable, utilize variable in printf this:

#include <stdio.h> void fahrenheit_temperature(double celcius_temp, double *fahrenheit_temp){ *fahrenheit_temp = (9.0 / 5.0) * celcius_temp + 32.0; } int main(void){ double fahrenheit_temp; fahrenheit_temperature(0.0, &fahrenheit_temp); printf("freezing point: %6.2f f.\n",fahrenheit_temp); fahrenheit_temperature(100.0, &fahrenheit_temp); printf("boiling point: %6.2f f.\n",fahrenheit_temp); homecoming 0; }

then not need alter homecoming type of function fahrenheit_temperature, maintain function out of printf statement - not homecoming value.

c pointers function-pointers

No comments:

Post a Comment