15,964,792 members
See more:
i need to write program which should add two distances and display the result in feet and inches. The initial distance is set in the beginning of the program, which should be modified according to the input of the user.
Posted
Richard MacCutchan 13-Dec-11 10:00am
Are you really saying this problem is beyond you? Try writing the steps required on a piece of paper and then convert it to code.

## Solution 1

Firstly convert all measurements to inches. Do the calculations as inches, then to display convert back to feet and inches.

## Solution 2

Try this one:

C#
```private void button1_Click(object sender, EventArgs e)
{
const int divider = 12;

double distance1 = double.Parse(textBox1.Text);
double distance2 = double.Parse(textBox2.Text);

double totalInches = distance1 + distance2;
double totalFeet = totalInches / divider;
MessageBox.Show("Total in inches: " + totalInches.ToString() + "Total in feet: " + totalFeet.ToString());
}```

Hope you get the logic from here. Did not included data input validation anymore :)

BTW, input here is fixed for inches you can try converting all input to inches first by creating a function that will return the converted values as inches equivalent.

Regards,
Eduard

v2
Richard MacCutchan 13-Dec-11 9:59am
I didn't actually tried this one
Guessed that.
[no name] 13-Dec-11 10:08am
yes i did! but my mind has intellisense for these kind of simple program logic formulation and i stand right for this one :)
Richard MacCutchan 13-Dec-11 10:10am
Try it.
[no name] 13-Dec-11 10:18am
sorry for that. lesson learned. improved solution. thanks btw! :)
Richard MacCutchan 13-Dec-11 11:25am
I have that sort of intellisense in my brain most days ;)