473,408 Members | 2,030 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,408 software developers and data experts.

Switch Statement Calculations

Hi im trying to create a switch statement which you see below. I created a combo box and Im trying to set constants if certain numbers are selected in the combo box. The error message that I am getting is "cannot implicity convert type 'double to 'string'. How can I set a constat to certain values using a switch statement. I have to calculate the number of hours rentted * the siz of the yacht (which are the constatnts). Thanks for any feedback.

here are the constats values:
Expand|Select|Wrap|Line Numbers
  1. const double YACHT_22 = 95.00;
  2. YACHT_24 =137.00;
  3. YACHT_30 = 160.00;
  4. YACHT_32 = 192.00;
  5. YACHT_36 = 250.00;
  6. YACHT_38 = 400.00;
  7. YACHT_45= 550.00;
  8.  
  9.  
  10.    double.Parse(comboBoxsizeofyacht.Text);
  11.  
  12.  
  13.             switch (comboBoxsizeofyacht.Text)
  14.             {
  15.                 case "22":
  16.                     comboBoxsizeofyacht.Text = YACHT_22;
  17.                     break;
  18.  
  19.                 case "24":
  20.                     comboBoxsizeofyacht.Text = YACHT_24;
  21.                     break;
  22.                 case " 30 ":
  23.                     comboBoxsizeofyacht.Text = YACHT_30;
  24.                     break;
  25.                 case " 32 ":
  26.                     comboBoxsizeofyacht.Text = YACHT_32;
  27.                 case " 36 ":
  28.                     comboBoxsizeofyacht.Text = YACHT_36;
  29.                     break;
  30.                 case "38":
  31.                     comboBoxsizeofyacht.Text = YACHT_38;
  32.                     break;
  33.                 case "45":
  34.                     comboBoxsizeofyacht.Text = YACHT_45;
  35.                     break;
  36.             }
Apr 24 '10 #1
5 2976
tlhintoq
3,525 Expert 2GB
The error message says it all.
error: "cannot implicity convert type 'double to 'string'
You are trying to set the .TEXT of the combo box (IE: a String) to the DECIMAL of value of a number. You can't do that. Convert the number to a string first.


Expand|Select|Wrap|Line Numbers
  1. comboBoxsizeofyacht.Text = YACHT_22.ToString();
Apr 24 '10 #2
tlhintoq
3,525 Expert 2GB
TIP: When you first created your question you were asked to wrap your code with [code] tags.

It really does help a bunch. Look how much easier it is to read now that someone has done it for you. Its the button with a '#' on it. More on tags. They're cool. Check'em out.
Apr 24 '10 #3
I do apologize I am new to all this. If it is converted to string, will I still be able to do the calculation? Its in a string format and I'm trying to take the constatnt value, and muliply by the number of hours the Yacht was rented.
Apr 24 '10 #4
GaryTexmo
1,501 Expert 1GB
You can always convert it from a string, back to a double ;)

Do a google on the conversion you want, it should turn up any information you need. Also, each of the primitive types have a "Parse" and "TryParse" method attached to them, look into those as well.
Apr 24 '10 #5
tlhintoq
3,525 Expert 2GB
YACHT_22 will always be a number.
.ToString() is a method that returns a string - but it doesn't alter the original variable it is attached to.
YACHT_22.ToString() will provide you a string version of YACHT_22 *that one time* on that one line
Apr 24 '10 #6

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

Similar topics

35
by: Thomas Matthews | last post by:
Hi, My son is writing a program to move a character. He is using the numbers on the keypad to indicate the direction of movement: 7 8 9 4 5 6 1 2 3 Each number has a direction except...
17
by: prafulla | last post by:
Hi all, I don't have a copy of C standard at hand and so anyone of you can help me. I have always wondered how switch statements are so efficient in jumping to the right case (if any)? Can...
18
by: swaroophr | last post by:
Which of switch statement and if-else statement takes less time to execute?
13
by: PeterZ | last post by:
Hi, Back to basics! My understanding is that the only way to exit a For-Next loop prematurely is with the 'break' keyword. How are you supposed to do that if you're inside a Switch...
1
by: Berko | last post by:
I'm having problems with a switch statement that is wrapped in a foreach statement so that each index in an array is evaluated against the switch statement. The switch/case will then return some...
19
by: rdavis7408 | last post by:
Hello, I have four textboxes that the user enters the price per gallon paid at the pump, the mileage per gallon and I would like to then calculate the cost per gallon and use a switch statement to...
4
by: priyanka | last post by:
Hi there, I had a question. Is there any way of testing a string value in a switch statement. I have about 50 string values that can be in a string variable. I tried cheking them with the if...
5
by: mark4asp | last post by:
Every time the function below is called I get the alert. So I put a deliberate error in there and I check the value of (reportType=='MANDATE') in Firebug, which is found to be true. But still the...
2
by: Phillip B Oldham | last post by:
What would be the optimal/pythonic way to subject an object to a number of tests (based on the object's attributes) and redirect program flow? Say I had the following: pets = {'name':...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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.