Functions

I am writing a program that lets a user enter a length in feet and inches and converts it into meters and centimeters. What is wrong with my code and how can I change it?

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
#include <iostream>
using namespace std;

double input();
double processing();
double output();

int main()
{
	char ans;
	do
	{
		input();
		processing();
		output();
		cout << "Do you wish to convert another measurement?\n";
		cin >> ans;
	} while (ans == 'y' || ans == 'Y');
	
	return 0;
}

double input(double l)
{
	cout << "Enter a length in feet and inches.\n";
	cin >> l;
	return l;
}

double processing(double l)
{
	double new_length;
	new_length = l ;
}

double output(double l)
{
	cout << l << endl;
}
Last edited on
You will have to be more specific as to the problem. What are the errors, and at what lines does your debugger locate them?
Your function declarations don't match up with your definitions:
1
2
3
4
5
6
7
8
9
10
11
12
// Your declarations:
double input();
double processing();
double output();

// What you've defined:
double input(double l)
{ /* ... */ }
double processing(double l)
{ /* ... */ }
double output(double l)
{ /* ... */ }

Remember that functions can't "see" variables declared inside other functions, so you'll need to make use of the return values and parameters to get information from one function and pass it to the next.
Your function prototypes do not have formal parameters, nor do your calls to the functions in main have arguments for the functions. However, in your definitions, you are stating that the functions input, processing and output should have formal parameters. You may also want to think about making some of your parameters in your definitions referenced. Also, you probably will want a return statement in your processing function. For the output function, think about why you want it to be double. A function that is not a void function should return a value.
Last edited on
I see some problems:

1. input asks for 2 things, only input 1
2. No conversion is done
3. Multiple problems with functions


Read the tutorial at the top left of this page.

First those functions with double you made must return something if i am right.
Thanks to everyone. My mistake if I didn't make it clear. I will use all of your advice and rework my program.
Last edited on
Topic archived. No new replies allowed.