Can someone help me fix this code?

I am supposed to put two functions in a header file set. I am supposed to generate a table converting celsius to fahrenheit and fahrenheit to celsius. However, I don't know how to utilize my .h file in my .cpp file. Can someone help me connect the two somehow? Please explain it in an easy to understand way because I am only a beginner. I tried reading tutorials but i just don't understand. Any help is appreciated! Thanks in advance :)
Below is the code in my .h file...I have also included the code in my .cpp file below that.
1
2
3
4
5
6
7
8
9
10
11
12
 #include <iostream>
using namespace std;

double f, c;
double celsiusToFahrenheit(double c) {
	
	return (( f - 32)* 5. / 9.);
}
double fahrenheitToCelsius(double f) {
	return (9. / 5. * (c + 32));
}


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
#include <iostream>
#include <iomanip>
#include <cmath>
#include <conio.h>
#include "convert.h"

using namespace std;

int main()
{
	cout << "Please enter degrees in fahrenheit: ";
	cin >> f;
	
	cout << "Please enter degrees in celsius:  ";
	cin >> c;
	
	double celsiusToFahrenheit(double c);

	double fahrenheitToCelsius(double f);

	
	cout << " Celsius to Fahrenheit" << setw(28)
		<< "Fahrenheit to Celsius " << endl << endl;

	
	cout << setw(8) << "Celsius" << setw(12) << "Fahr "
		<< setw(12) << "Fahr " << setw(14) << "Celsius" << endl << endl;

	
	for (double c = 0; c <= 100; c += 5)
	{
		for (double f = 0; f <= 5; f += 25)

			
			cout << setw(6) << setprecision(0) << c + f << setw(13)
			<< setprecision(2) << fixed << celsiusToFahrenheit(c + f) << ' '
			<< setw(10) << setprecision(0) << c + f << setw(15)
			<< setprecision(2) << fixed << fahrenheitToCelsius(c + f) << ' ';
		cout << endl;
	}
	_getch();
	return 0;

} 
keskiverto: yes it was. I'm still confused so any help or advice you could give me would be very appreciated
So, what is the problem? You've included your header file in your cpp file. That's all you
need.
Other than that, remove
1
2
3
        double celsiusToFahrenheit(double c);

	double fahrenheitToCelsius(double f);

from main.
the problem is my table is not outputting the correct results. it seems like the calculations my program is supposed to make is not getting put into the table at all
What should it output? A "table", yes, but for what range of values?

If you have on same table columns C, F, C, aren't the first and last columns identical (unless two conversions introduces rounding errors)?

Perhaps there should be two tables, first with some range of C and calculated F, and the second with some range of F and calculated C?


Global variables is a no and global variables on a header is a huge NO.

Lines 11-15 achieve nothing.

For loop at line 32 executes only one iteration, with f==0.

The c and f declared on lines 30 and 32 hide the global c and f. Furthermore, their names are not intuitive.
its supposed to be a table that displays celsius converted to fahrenheit showing both values side by side with another table that says fahrenheit converted to celsius. for celsius to fahreneheit it should be 40.0 C down to 31.0 C and the conversions. for fahrenheit to celsius it should be 120.0 F down to 30 F. also i edited my code
header:
1
2
3
4
5
6
7
8
9
10
11
#include <iostream>

using namespace std;

double celsiusToFahrenheit(double dTempInC) {
	return ((dTempInC - 32.0)* 5. / 9.);
}

double fahrenheitToCelsius(double dTempInF) {
	return (9. / 5. * (dTempInF + 32.0));
}


main:
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 <iostream>
#include <iomanip>
#include <cmath>
#include <conio.h>
#include "convert.h"

using namespace std;

int main()
{
	double f, c;
	cout << "Please enter degrees in fahrenheit: ";
	cin >> f;
	
	cout << "Please enter degrees in celsius:  ";
	cin >> c;
	
	for (double i = 0; i <= 100; i+= 5) {
		cout << "Celsius  " << i << "Fahrenheit " << celsiusToFahrenheit(i) << endl;
	}

	for (double i = 32; i <= 215; i+= 5) {
		cout << "Fahrenheit  " << i << setw(15) << "Celsius  " << fahrenheitToCelsius(i) << endl;
	}
	}
The header:
* Remove lines 1 and 3, for they are not used.
* Recheck the equations.

The main:
* Lines 4, 11-16 have no purpose.
* Line 18. You said "from 40 to 31", but the code does "from 0 to 100 in steps of 5".
* Line 22. You said "from 120 to 30", but the code does "from 32 to 215 in steps of 5".
Topic archived. No new replies allowed.