Temperature Conversion using Module

Struggling with getting my int main to use the equation in my module

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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
  #include <iostream>
#include <string>
#include <iomanip>

 using namespace std;
 
 void showF(float fahrenheit , float celsius) ;


int main()
{
		
float fahrenheit = 0;
	float celsius = 0;
	


	// Input Block
cout << "Please enter your temperature in Fahrenheit.\n";
cin >> fahrenheit ;

showF( fahrenheit,  celsius);
	
	
	//Output Block
	cout << std:: setprecision(2) << std::fixed;
	
	cout << fahrenheit <<" degrees fahrenheit is equal to " << celsius << " degrees"<< endl;
	
	
	

	
	
	
	
	
system ("pause");	

return 0;
	
	
}

 void showF(float fahrenheit , float celsius)
{
	
  
	celsius = ((fahrenheit - 32) * 5) / 9;

	
}
Actually solved the problem if anyone else is another struggling beginner. i put the change below

#include <iostream>
#include <string>
#include <iomanip>

using namespace std;

void showF(float fahrenheit , float celsius) ;


int main()
{

float fahrenheit = 0;
float celsius = 0;



// Input Block
cout << "Please enter your temperature in Fahrenheit.\n";
cin >> fahrenheit ;

showF( fahrenheit, celsius);












system ("pause");

return 0;


}

void showF(float fahrenheit , float celsius)
{


celsius = ((fahrenheit - 32) * 5) / 9;

//Output Block
cout << std:: setprecision(2) << std::fixed;

cout << fahrenheit <<" degrees Fahrenheit is equal to " << celsius << " degrees Celsius. "<< endl;


}
Hello hdbuck2,

PLEASE ALWAYS USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post.
http://www.cplusplus.com/articles/jEywvCM9/
http://www.cplusplus.com/articles/z13hAqkS/
Hint: You can edit your post, highlight your code and press the <> formatting button.
You can use the preview button at the bottom to see how it looks.

Doubles are preferred over floats.

There are two other ways to solve your original problem.

1. Have the function celsius. double showF( double const fahrenheit, double const celsius);

or

2. Pass celsius by reference. void showF( double const fahrenheit, double& celsius);

Hope that helps,

Andy
Topic archived. No new replies allowed.