Click here to Skip to main content
15,606,617 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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.
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.

Firstly convert all measurements to inches. Do the calculations as inches, then to display convert back to feet and inches.
Share this answer
Try this one:

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.

Share this answer
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 ;)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900