I can't find the problem.

Hey everyone, I'm having to write a program that allows the user to input a certain amount of feet and Inches and then have it converted to meters and centimeters. I was wondering if anyone could help me fix this mess I've made?

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;

void input(double &feet, double &inches);
void conversion (double feet, double &inches, int &meters, double &centimeters);
void output(int meters, double centimeters);   

int main ()
 
{
	int meters;
	double feet, inches, centimeters;
	char menu;

	do
	{
		cout << "Do You Want To Continue?(Y/N): ";
		cin >> menu;
		input(feet, inches);
		conversion(feet, inches, meters, centimeters);
		output (meters, centimeters);

	}while (menu == 'Y' || menu == 'y');
}

void input(double &feet, double &inches)
{
	cout << "Enter number of feet: ";
	cin >> feet;
	cout << "Enter number of inches: ";
	cin >> inches;
}

void conversion (double feet, double &inches, int &meters, double &centimeters)
{
	inches += 12 * feet;
	centimeters = inches * 2.54;
	meters = centimeters/100;
	centimeters -= meters*100;
}

void output (int meters, double centimeters)
{
	cout << meters << " meters and " << centimeters << "cm " << endl;
}
 
return 0:
}
closed account (DEUX92yv)
Just out of curiosity, what is the problem you're referring to?
It seems like it's hung up on the "meters conversion," which I don't exactly understand why.
The problem I see (which may not be the one you are asking about), is the question "Do You Want To Continue?(Y/N): ". Regardless of the answer, the program then requests the feet and inches, and prints the result.

Only after doing that does it get around to testing the answer (y or n) to the question. One way around this is to ask that question just before the end of the loop, not just at the beginning.

How you handle this really depends on what is the required behaviour of the program.
Last edited on
Thank you Chervil. That makes sense to me, I appreciate you pointing that out.
Topic archived. No new replies allowed.