visual studio 2010 - Distance Converter for inches, feet, and yards in C# -
i new programming, silly question simple answer. application allows users type number, select unit of measurement using, select unit of measurement convert , convert it.
i have 1 error in last line of code keeping working: 'cannot implicitly convert type 'int' 'string'. can please help?
here's code:
private void convertbutton_click(object sender, eventargs e) { int fromdistance; int todistance; fromdistance = int.parse(distanceinput.text); string measureinput = fromlist.items[fromlist.selectedindex].tostring(); string measureoutput = tolist.items[tolist.selectedindex].tostring(); switch (measureinput) { case "yards": switch (measureoutput) { case "yards": todistance = fromdistance; break; case "feet": todistance = fromdistance * 3; break; case "foot": todistance = fromdistance * 3 * 12; break; } break; case "feet": switch (measureoutput) { case "feet": todistance = fromdistance; break; case "yards": todistance = fromdistance / 3; break; case "foot": todistance = fromdistance * 12; break; } break; case "foot": switch (measureoutput) { case "foot": todistance = fromdistance; break; case "feet": todistance = fromdistance / 12; break; case "yards": todistance = fromdistance / (3 * 12); break; } break; } distanceoutput.text = todistance; }
distanceoutput.text = todistance.tostring();
looks might used dynamically typed languages? int stored in binary representation, , can represent many different values. .tostring() converts common representation.
btw should not use integer calculated value type, you'll throw away fractional numbers. use double or float, , use math.round(number, decimalpoints) .
Comments
Post a Comment