Can anyone give me a hand with this code!? any help would be greatly apreciated!!!

I cant get this code to run properly! The error code that comes up is saying that get_input is not intalized. but here is wat i need to accomplish--->
/*****************************************************
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).
********************************************************/

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

int main()
{
       introduction();
       get_input();
       get_output(choice);

       return 0;
} 
void introduction()
{
       cout << "Would you like to convert lengths or weights?" << endl;
       cout << "Please enter 1 for lengths, 2 for weights," << endl;
       cout << "and 0 if you wish to end the program" << endl;
}
void get_input()
{
       cout << "Please enter your choice: ";
       cin >> choice;       
}
void get_output(double& choice)
{
       if(choice == 1)
       {
              value = convert_lengths(choice, value, lengths);
       }
       if(choice == 2)
       {
              value = convert_weights(choice, value, weights);
       }
}
double convert_lengths(double choice, double value, double lengths)
{
       return 1;
}
double convert_weights(double choice, double value, double weights)
{
       return 2;
}
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
#include <iostream>
using namespace std;

double convert_lengths(double choice, double value, double lengths)
{
	return 1;
}

double convert_weights(double choice, double value, double weights)
{
	return 2;
}

void introduction()
{
	cout << "Would you like to convert lengths or weights?" << endl;
	cout << "Please enter 1 for lengths, 2 for weights," << endl;
	cout << "and 0 if you wish to end the program" << endl;
}

void get_input(double& choice)
{
	cout << "Please enter your choice: ";
	cin >> choice;       
}

void get_output(double choice, double lengths, double weights, double& value)
{
	if(choice == 1)
	{
		value = convert_lengths(choice, value, lengths);
	}
	if(choice == 2)
	{
		value = convert_weights(choice, value, weights);
	}
}

int main()
{
	double choice(1), value(0), lengths(0), weights(0);

	introduction();
	get_input(choice);
	get_output(choice, lengths, weights, value);

	return 0;
} 
okay i pluged it in. this is the error that i am stil getting--->
1>MSVCRTD.lib(crtexew.obj) : error LNK2019: unresolved external symbol _WinMain@16 referenced in function ___tmainCRTStartup
1>C:\comp141\jan23b\Debug\jan23b.exe : fatal error LNK1120: 1 unresolved externals

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

#include <iostream>
using namespace std;

double convert_lengths(double choice, double value, double lengths)
{
	return 1;
}

double convert_weights(double choice, double value, double weights)
{
	return 2;
}

void introduction()
{
	cout << "Would you like to convert lengths or weights?" << endl;
	cout << "Please enter 1 for lengths, 2 for weights," << endl;
	cout << "and 0 if you wish to end the program" << endl;
}

void get_input(double& choice)
{
	cout << "Please enter your choice: ";
	cin >> choice;       
}

void get_output(double choice, double lengths, double weights, double& value)
{
	if(choice == 1)
	{
		value = convert_lengths(choice, value, lengths);
	}
	if(choice == 2)
	{
		value = convert_weights(choice, value, weights);
	}
}

int main()
{
	double choice(1), value(0), lengths(0), weights(0);

	introduction();
	get_input(choice);
	get_output(choice, lengths, weights, value);

	return 0;
}
Take the following out from the top of your code:

1
2
3
4
5
6
7
8
9
10
void introduction();
void get_intput(double choice);
void get_output(double& choice);
double convert_lengths(double choice, double value, double lengths);
double convert_weights(double choice, double value, double weights);
double choice;
double conversion;
double value;
double weights;
double lengths;
thank you so much ajh32! I was trying to get the last part of the program to work....-->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--->but i not sure if i should use a loop or and if else statement! and where i should put it...
How about a very small change:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
int main()
{
	double choice(1), value(0), lengths(0), weights(0);

	introduction();

	while (choice != 0)
	{
		get_input(choice);
		get_output(choice, lengths, weights, value);
	}

	return 0;
}
Thank you again ajh32!! helped alot!!! But last question....how was the top part of my code a problem?
As long as your function prototypes exactly match your function declarations you are fine. I have also slightly amended the code so that 'get_input' will return a Boolean; false to exit program. Plus added a switch() statement in 'get_output'.

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

// function protypes:
void introduction();
bool get_input(int& choice);
void get_output(int choice, double lengths, double weights, double& value);
double convert_lengths(int choice, double value, double lengths);
double convert_weights(int choice, double value, double weights);

int main()
{
	int choice(1);
	double value(0), lengths(0), weights(0);

	introduction();

	while (choice != 0)
	{
		if (get_input(choice))
			get_output(choice, lengths, weights, value);
	}

	return 0;
} 

void introduction()
{
	cout << "Would you like to convert lengths or weights?" << endl;
	cout << "Please enter 1 for lengths, 2 for weights," << endl;
	cout << "and 0 if you wish to end the program" << endl;
}

bool get_input(int& choice)
{
	cout << "Please enter your choice: ";
	cin >> choice;   
	return choice != 0;
}

void get_output(int choice, double lengths, double weights, double& value)
{
	switch (choice)
	{	
	case 1:
		value = convert_lengths(choice, value, lengths);
		break;
	case 2:
		value = convert_weights(choice, value, weights);
		break;
	}
}

double convert_lengths(int choice, double value, double lengths)
{
	return 1;
}

double convert_weights(int choice, double value, double weights)
{
	return 2;
}
Topic archived. No new replies allowed.