I dont know why this function is not working. Could you tell me how to get it to work.

its a simple tempertature conversion code. I know that it is for the most part incomplete for the second half of the code. I want it to print out with the
fahrenheit temperature on one side and the celsius on another, while still using at least one function.
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include <iostream>
#include <iomanip>
#include <stdlib.h>
#include <cmath>
using namespace std;

double calcfahrenheit (double start, double end, double between);
double calccelsius(double start, double end, double between);
double calcf(double celsius);
int main()
{
	int choice;
	double tstart, tend, tinterval;
	double fahrenheit;

	cout << "Which Temperature Scale Converstion Would You Like To Perform?\n";
	cout << "1. Convert F to C\n";
	cout << "2. Convert C to F\n";
	cout << endl;
	cout << "What is your choice? ";
	cin >> choice;
	cout << endl;
	
	
	switch(choice)
	{
		case 1:
			cout << "Starting Temperature: ";
			cin >> tstart;
			cout << "Ending Temperature: ";
			cin >> tend;
			cout << "Temperture Increase: ";
			cin >> tinterval;
			cout << "Fahrenheit" << setw(12) << "Celsius\n";
			cout << "----------" << setw(12) << "-------\n";
			fahrenheit = calcfahrenheit(tstart,tend, tinterval);
			cout << tstart << setw(10) << fahrenheit << endl;
			break;
		case 2:
			cout << "Starting Temperature: ";
			cin >> tstart;
			cout << "Ending Temperature: ";
			cin >> tend;
			cout << "Temperture Increase: ";
			cin >> tinterval;
			cout << "Celsius" << setw(12) << "Fahrenheit\n";
			cout << "-------" << setw(12) << "----------\n";
			calccelsius(tstart, tend, tinterval);
			break;
		default:
			cout << "You entered an incorrect code\n";
			break;
	}

	system("pause");
	return 0;
}
double calcfahrenheit(double start, double end, double between)
{	
	double hope;
	for(start; start <= end; start += between)
		{
			calcf(faith)
			hope =  calcf(faith);
			cout << start << setw(12) << hope << endl;
		}
			return start;
		
}
double calccelsius(double start, double end, double between)
{
	for(start; start <= end; start += between)
	{
			cout << start << setw(12) << end << endl;
			
	}
	return start;
}
double calcf(double faith)
{
	double constant = 32;
	double multi1 = 9.0;
	double multi2 = 5.0;
	double quotiant;
	double sum;
	double please;
	please = calcfahrenheit(tstart, tend, tbetween);
	sum =  please - constant;
	quotiant = multi1/multi2;
	faith = sum*quotiant;
}
	
you over complicate things. Read this:

http://en.wikipedia.org/wiki/Fahrenheit


line 87 makes no sense at all.
You need to think of much more sensible names. That will make you see how things work.

So if you want to calculate fahrenheit from Celsius, name the function like so:
1
2
3
4
double GetFahrenheitFromCelsius(double celsius)
{
  return celsius * 9 / 5 + 32;
}
This code would be much easier if you put most of your code inside of your functions. You are also asking for too much information. All you need is the number that the user wants converted, then convert and output within your functions. No need for start, end or increase. Code is suppose to be simple and efficient, not long and complicated.
And you shouldn't use doubles in for loops.

Floating point values are stored as binary fractions and cannot represent every real number. When you initialise a FP number X, you usually get X +/- a small amount - for doubles this is about 1e-16, this number is known as epsilon when X is 1.0. The for loop can fail on the end condition (or at least do 1 more iteration than what you thought) because the number can be less than the exact value by the epsilon amount.

So, always use integers in loop conditions & convert them to double inside the loop.

Hope all goes well.
Topic archived. No new replies allowed.