473,399 Members | 3,888 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

how can i fix this error?

hi all,

i am writing a weight conversion program that allows the user to input their weight, however i keep getting the same error saying operator '\' cannot be applied to operands of type decimal and double. can anyone help me with this?

here is my code

Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4.  
  5. namespace WeightConverter
  6. {
  7.     class WeightConverter
  8.     {
  9.  
  10.         static void Main(string[] args)
  11.         {
  12.             //declare variables
  13.             int selection = 0;
  14.  
  15.  
  16.  
  17.             while (selection < 5)
  18.             {
  19.  
  20.                 try
  21.                 {
  22.                     //Ask's the user to select a type to be converted
  23.                     Console.WriteLine("Select type:" +
  24.                         "\n1) Metric to Imperial\n2) Imperial to Metric\n3) Exit the program.\n");
  25.                     selection = Convert.ToInt32(Console.ReadLine());
  26.  
  27.                     /*if statement which checks if the user wanted to end the
  28.                       program of if they entered a selection between 1 and 5*/
  29.                     if (selection == 5)
  30.                         Console.WriteLine("Exiting program.");
  31.                     else if (selection < 1 || selection > 3)
  32.                         Console.WriteLine("Please enter a selection between 1 and 5.\n");
  33.                     else
  34.                         SelectionMethod(selection);
  35.                 }//end try
  36.                 //if input value is not numeric, display message
  37.                 catch
  38.                 {
  39.                     Console.WriteLine("Invalid input value.");
  40.                 }//end catch
  41.             }//end while
  42.  
  43.         }//end Main method
  44.  
  45.         public static int SelectionMethod(int s)
  46.         {     
  47.             //declare variables and create reference to WeightConverter class
  48.             WeightConverter weightConverter = new WeightConverter();
  49.  
  50.             decimal kilograms = 0;
  51.             decimal pounds = 0;
  52.  
  53.  
  54.             try
  55.             {
  56.  
  57.                 switch (s)
  58.                 {
  59.  
  60.                     //if user chose to input kilograms, prompt user to enter how many
  61.                     case 1:
  62.                         Console.WriteLine("Input amount of kilograms to be conveted:\n");
  63.                         kilograms = Convert.ToDecimal(Console.ReadLine());
  64.  
  65.                         //call Kilograms method of class WeightConverter
  66.                         weightConverter.Kilograms(kilograms);
  67.                         break;
  68.  
  69.  
  70.                     //if user chose to input pounds, prompt user to enter how many
  71.                     case 2:
  72.                         Console.WriteLine("Input amount of pounds to be converted:\n");
  73.                         pounds = Convert.ToDecimal(Console.ReadLine());
  74.  
  75.                         //call Pounds method of class WeightConverter
  76.                         weightConverter.Pounds(pounds);
  77.                         break;
  78.                 }
  79.             }//end try
  80.             //if input value is not numeric, display message
  81.             catch
  82.             {
  83.                 Console.WriteLine("Invalid input value.");
  84.             }//end catch
  85.  
  86.             return s;
  87.         }//end Selection method
  88.  
  89.         public decimal Kilograms(decimal kg)
  90.         {
  91.             decimal pounds = 0;
  92.             int selection = 0;
  93.             while (selection <= 2)
  94.             {
  95.                 try
  96.                 {
  97.                     //ask's the user to select what they would like to convert grams to
  98.                     Console.WriteLine("Convert Kilograms to?\n1) Pounds" +
  99.                             "\n2) Return to first selection.");
  100.                     selection = Convert.ToInt32(Console.ReadLine());
  101.  
  102.                     switch (selection)
  103.                     {
  104.  
  105.                         //convert kilograms to pounds
  106.                         case 1:
  107.                             Kilograms = pounds / 2.2046;  
  108.  
  109.                             Console.WriteLine("{0} kilogram(s) is {1} pound(s).", kg, pounds);
  110.                             break;
  111.  
  112.                         //return to first selection
  113.                         case 2:
  114.                             selection = 5;
  115.                             break;
  116.  
  117.                     }
  118.                 }//end try
  119.                 //if value entered is not numeric, display message
  120.                 catch
  121.                 {
  122.                     Console.WriteLine("Invalid input value.");
  123.                 }//end catch
  124.             }//end while
  125.             return kg;
  126.         }
  127.  
  128.  
  129.         public decimal Pounds(decimal p)
  130.         {
  131.             decimal kilograms = 0;
  132.             int selection = 0;
  133.             while (selection <= 2)
  134.             {
  135.                 try
  136.                 {
  137.                     //prompt user to select what they would like to convert grams to
  138.                     Console.WriteLine("Convert pounds to?\n1) Kilograms\n2) Return to first selection.");
  139.                     selection = Convert.ToInt32(Console.ReadLine());
  140.  
  141.                     switch (selection)
  142.                     {
  143.                         //convert pounds to kilograms
  144.                         case 1:
  145.                             Pounds = kilograms / 0.453;
  146.  
  147.                             Console.WriteLine("{0} pound(s) is {1} kilogram(s).", p, kilograms);
  148.                             break;
  149.  
  150.  
  151.                         //return to first selection
  152.                         case 2:
  153.                             selection = 5;
  154.                             break;
  155.  
  156.                     }
  157.                 }//end try
  158.                 //if value entered is not numeric, display message
  159.                 catch
  160.                 {
  161.                     Console.WriteLine("Invalid input value.");
  162.                 }//end catch
  163.             }//end while
  164.             return p;
  165.         }
  166.     }
  167.         }
Mar 6 '10 #1
3 1434
tlhintoq
3,525 Expert 2GB
TIP: When you are writing your question, there is a button on the tool bar that wraps the [code] tags around your copy/pasted code. It helps a bunch. Its the button with a '#' on it. More on tags. They're cool. Check'em out.
Mar 6 '10 #2
tlhintoq
3,525 Expert 2GB
You left a lot of code. On what line do you get that error message?
Mar 6 '10 #3
tlhintoq
3,525 Expert 2GB
If you are trying divide you want to use / not \
Mar 6 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: AIM | last post by:
Error in msvc in building inheritance.obj to build hello.pyd Hello, I am trying to build the boost 1.31.0 sample extension hello.cpp. I can not compile the file inheritance.cpp because the two...
2
by: Gregory | last post by:
Hi, One of the disadvantages of using error handling with error codes instead of exception handling is that error codes retuned from a function can be forgotten to check thus leading to...
13
by: deko | last post by:
I use this convention frequently: Exit_Here: Exit Sub HandleErr: Select Case Err.Number Case 3163 Resume Next Case 3376 Resume Next
7
by: p | last post by:
WE had a Crystal 8 WebApp using vs 2002 which we upgraded to VS2003. I also have Crystal 9 pro on my development machine. The web app runs fine on my dev machine but am having problems deploying....
3
by: Manuel | last post by:
I'm trying to compile glut 3.7.6 (dowbloaded from official site)using devc++. So I've imported the glut32.dsp into devc++, included manually some headers, and start to compile. It return a very...
0
by: bazzer | last post by:
hey, im trying to access a microsoft access database from an ASP.NET web application in visual basic 2003.NET. i get the following error when i try running it: Server Error in...
1
by: developer | last post by:
Hi All I have made a .NET project. the files included are borland c++ files that i am migrate to VC++ .NET I am using Microsoft Visual C++ .NET 2003. the compilation goes through properly,...
0
by: mchuc7719 | last post by:
Hello, I have a Vb.Net 2005 ClassLibrary, when I try to compile using MSBee, only get errors. Before I to run the command line, I open in notepad the .vbproj and I was add the next line: ...
2
hyperpau
by: hyperpau | last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding. I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com). Ergo, I...
0
hyperpau
by: hyperpau | last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding. I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com). Ergo, I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.