Please Help! Function does not take 1 parameters

My program converts from Fahrenheit to Celsius and vice versa, with the option of displaying the Kelvin temperature with a Y/N message. When compiling, two error messages pop up saying function does not take 1 parameters in regards to the showDegreesK function. Can someone figure out what I need to do to fix this?

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
#include "stdafx.h"
#include <iostream>

using namespace std;
using namespace System;

double FtoC(double t);
double CtoF(double t);
double showDegreesK(char kchoice, int, double);

int main()
{
	double temp, result;
	int choice;
	char kchoice;

	cout << "Welcome to the temp conversion program." << endl;

	do
	{
		cout << "Would you like to see degrees Kelvin (K) in the results? (Y/N): ";
		cin >> kchoice;
		cout << "\nConversion Type (1=F to C, 2=C to F, 0=Quit: ";
		cin >> choice;

		if (choice == 1)
		{
			cout << "Enter your Fahrenheit temp: ";
			cin >> temp;

			result = FtoC(temp);
			cout << "A temp of " << temp << "F is equal to " << result << "C." << endl;
			showDegreesK(kchoice);
		}

		else if (choice == 2)
		{
			cout << "Enter your Celcius temp: ";
			cin >> temp;

			result = CtoF(temp);
			cout << "A temp of " << temp << "C is equal to " << result << "F." << endl;
			showDegreesK(kchoice);
		}
	} while (choice != 0);

	cout << "\nThanks for using the temp converter!" << endl;
	system("Pause");
    return 0;
}

double FtoC(double t)
{
	double r;
	r = (5.0/9.0 * (t - 32.0));

	return r;
}

double CtoF(double t)
{
	double r;
	r = ((9.0 / 5.0) * t) + 32;

	return r;
}

double showDegreesK(char kchoice, int choice, double result)
{
	double kresult;

	if (kchoice == 'Y' && choice == 1)
	{
		kresult = result + 273.15;
	}

	else if (kchoice == 'Y' && choice == 2)
	{
		kresult = (result + 459.67) * (5.0/9.0);
	}

	return kresult;
}
The showDegreesK function have three parameters (kchoice, choice and result) but you are only passing one argument (kchoice).
I've put choice and result in the parameter and more errors show up. Can you show me what to change for the code to work?
The problem is when you call the function.

 
showDegreesK(kchoice); // You only pass one argument but the function expects three. 

If you only want to pass one argument to the function you need to change the function (line 9 and 68) so that it only have one parameter.
You need to think about what showDegrees() should do. Looking at your main program, I suggest something like:
1
2
// If kchoice is 'Y' then convert "celcius" to kelvin and print it.
// In either case, print a newline 

Now write that code to do that:
1
2
3
4
5
6
7
8
9
10
11
// If kchoice is 'Y' then convert "celcius" to kelvin and print it.
// In either case, print a newline
void
showDegreesK(char kchoice, double celcius)
{
    if (kchoice == 'Y') {
        double kelvin = celcius + 273.15;
        cout << " and " << kelvin << 'K';
    }
    cout << endl;
}


This is an important point: decide what your functions should do first, then write code to do that.

Change the declaration at line 9 to match this definition.

Also don't print the endl at lines 32 and 42. showDegrees will do that for you.
Last edited on
Topic archived. No new replies allowed.