Can anyone help me with this? any help would be greatly appreciated!

Okay here is a program that i have to write but i cant seem to get to run with what i have.

/*****************************************************
Write a program that asks the user if he or she wants to convert values that are lengths or weights. If the user chooses lengths, the program calls a stub function convert_lengths that simply indicates the user’s choice. If the user chooses weights, the program calls a stub function convert_weights that simply indicates the user’s choice. Use the value 1 to indicate lengths and the value 2 to indicate weights. If the user enters 0, terminate the program. The program should continue to prompt the user for input until he or she correctly enters a value of 0, 1, or 2. In addition, the program should allow the user to call convert_lengths or convert_weights as many times as desired (i.e., until a value of 0 is input, indicating that the user is finished).
********************************************************/



#include <iostream>
using namespace std;
void introduction();
void get_intput(double value);
void get_output(double& value);
double convert_lengths(double lengths);
double convert_weights(double weights);


void introduction()
{
cout << "this program will convert lengths and weights" << endl;
}
void get_intput(double value)
{
cout << "would you like to convert? 1, 2 or 0." << endl;
cin >> value;

}
void get_output(double& value)
{

if(value=1)
cout << convert_lengths << endl;
else if(value=2)
cout << convert_weights << endl;
else
{
cout << "end program" << endl;
}
}
double convert_lengths(double lengths)
{
return 1;
}
double convert_weights(double lengths)
{
return 2;

}
Here is your code reposted with code tages. Please use code tags in the future.
If you don't know what they are, its the button that looks like this <> to the right of your screen when you are posting.


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
#include <iostream>
using namespace std;
void introduction();
void get_intput(double value);
void get_output(double& value);
double convert_lengths(double lengths);
double convert_weights(double weights);


void introduction()
{
	cout << "this program will convert lengths and weights" << endl;
}
void get_intput(double value)
{
	cout << "would you like to convert? 1, 2 or 0." << endl;
	cin >> value;

}
void get_output(double& value)
{

	if(value=1)
		cout << convert_lengths << endl;
	else if(value=2)
		cout << convert_weights << endl;
	else
	{
		cout << "end program" << endl;
	}
}
double convert_lengths(double lengths)
{
	return 1;
}
double convert_weights(double lengths)
{
	return 2;

} 




You need a function main to start with. Create a function main, and then call your functions from main. You will need to use a loop, that exits when 0 is pressed. Your tag functions convert_lengths should output lenght, and convert_weights should output weights. The fucniton output isn't really needed here. Also in your introduction function you need to tell the user what they are expected to input. It just say's press 1,2, or 0.
Last edited on
I understand but thank you for your help Yanson! Where i am struggling is how to properly call the functions from main...as far as ending the loop i shouldnt have a problem with that. Though, how would the code look for main?
I'll give you a skeleton program



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
//preprocessor directives example 
#include <filename>

//function prototypes example
void functionName(parameter list);


int main()
{

//variable declareations example 
int variable = 0;


//function call example
functionName(arguments list);


return 0;
}

//function header
void functionName (parameter list)
{
      //function definitions

}



Topic archived. No new replies allowed.