Celsius to Fahrenheit using Pass by Values

I cant seem to make it work can anyone help me?


#include <stdio.h>
#include <stdlib.h>

float cf(int *c)
{
float fen;
fen = (1.8 * (*c)) + 32;
return fen;

int main()
{
float cel, fen;

printf ("Enter the value of Temperature in Celcius: ");

scanf ("%f", &cel);
fen = cf(&c);
printf ("The value of Temperature in Fahreinheit is: %.2f", fen);


system("PAUSE");
return 0;
}
This should work:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <stdio.h>
#include <stdlib.h>

float cf(int *c)
{
float fen;
fen = (1.8 * (*c)) + 32;
return fen;
}

int main()
{
float cel, fen;
int c;

printf ("Enter the value of Temperature in Celcius: ");

scanf ("%f", &cel);
fen = cf(&c);
printf ("The value of Temperature in Fahreinheit is: %.2f", fen);


system("PAUSE");	
return 0;
}


@OP(original poaster): Please use code tags.
Your errors:
-You did not end the definition of function cf
-You called it wrongly
Last edited on
the answer still does not come out right
but it helped..but still does not work

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <stdio.h>
#include <stdlib.h>

float cf(int *cal)
{
float fen;
fen = (1.8 * (*cal)) + 32;
return fen;
}

int main()
{
float c;

printf ("Enter the value of Temperature in Celcius: ");

scanf ("%f", &c);

printf ("The value of Temperature in Fahreinheit is: %.2f\n", cf(&c));


system("PAUSE");	
return 0;
}
tell me the conversion rate please cause I don't know.
as in celsius to kelvin is either +273 or -273 so what is that of celsius to fahrenheit?
Last edited on
http://lmgtfy.com/?q=celcius+to+farenheit

celcius temp * 9 / 5 + 32 = Fahrenheit

float cf(int *cal)
...
float c;

you are using &c and c is a float

so change it to

float cf(float *cal)
Last edited on
Thanks Maniax.

C++ code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>

using namespace std;

int main()
{
	double celcius;
	double far;
	int x=10;
	
	do{
	system("CLS");
	cout<<"Please enter a value to be converted to fahrenheit: ";
	cin>>celcius;
	far=celcius*9/5+32;
	cout<<"\nAns: "<<far;
	cout<<"\n\n\t\t\t\t\t\t\t\tContdown: "<<x-1;
	x--;
	cin.ignore();
	cin.get();
 } while(x!=0);
}
Topic archived. No new replies allowed.