# Help with Car Calculator

Page 1 of 1

## 13 Replies - 1784 Views - Last Post: 18 July 2009 - 06:57 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'https://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=115527&amp;s=7d4be122f92f8b0e93a9f7a836c19e72&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 juice33

• New D.I.C Head

Reputation: 0
• Posts: 12
• Joined: 18-July 09

# Help with Car Calculator

Posted 18 July 2009 - 01:58 PM

```Module Module1
Dim BasePrice As Decimal

Sub Main()

Console.WriteLine("Welcome to Universal Motors")
Console.Write("Enter the base price")
Console.WriteLine("")
Console.WriteLine("Engine Choice")
Console.WriteLine("S - 6 cyclinder engine")
Console.WriteLine("E - 8 cyclinder engine")
Console.WriteLine("D - Diesal Engine")
Console.WriteLine("Selection?  : ")

Dim EngineCost As String

Select Case EngineCost
Case ("S")
EngineCost = 150
Case ("E")
EngineCost = 475
Case ("D")
EngineCost = 750
End Select

Console.WriteLine("Enter TrimChoice")
Console.WriteLine(" V - Vinyl interior trim")
Console.WriteLine(" C - Cloth interior trim")
Console.WriteLine(" L - Leather interior trim")
Console.WriteLine("Selection?   : ")
Dim TrimCost As StringSplitOptions
Select Case TrimCost
Case ("V")
TrimCost = CStr(50)
Case ("C")
TrimCost = CStr(225)
Case ("L")
TrimCost = CStr(800)

End Select

Console.WriteLine("R - AM/FM")
Console.WriteLine("D - CD/DVD")
Console.WriteLine("Selection?  : ")
Dim RadioCost As StringSplitOptions

Case ("R")
Case Else
End Select

Dim ShippingCharge, DealerCharge, SellingPrice As String
ShippingCharge = 500
DealerCharge = 175

SellingPrice = BasePrice + ShippingCharge + DealerCharge + EngineCost + TrimCost + RadioCost

Console.Write("The total selling price for your vehicle is :\$  " + SellingPrice)
Console.WriteLine("")
Console.WriteLine("... Press the [Enter] key to exit.")

End Sub

End Module
```

** Edit **

Is This A Good Question/Topic? 0

## Replies To: Help with Car Calculator

### #2 juice33

• New D.I.C Head

Reputation: 0
• Posts: 12
• Joined: 18-July 09

## Re: Help with Car Calculator

Posted 18 July 2009 - 02:36 PM

```Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Dim AnnualIncome, TaxDue As Double
If AnnualIncome <= 50000 Then
' 5% tax bracket
TaxDue = AnnualIncome * 0.05
ElseIf AnnualIncome >= 50000 <= 100000 Then
' 7% tax bracket
TaxDue = 2500 + ((AnnualIncome) * 0.07)
ElseIf AnnualIncome >= 100000 Then
' 9% tax bracket
TaxDue = 6000 + ((AnnualIncome) * 0.09)
TaxDue = Convert.ToDecimal(btnCalculateIncomeTax.Text)
lblTaxDue.Text = TaxDue.ToString()
End If

End Sub

Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click

End Sub

Private Sub txtTaxableincome_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtTaxableIncome.TextChanged

End Sub

Private Sub btnCalculateIncomeTax_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculateIncomeTax.Click

End Sub

Private Sub lblTaxDue_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblTaxDue.Click

End Sub

End Class

```

Mod Edit: Please use code tags when posting your code. Code tags are used like so =>

Thanks,
PsychoCoder

### #3 LoveIsNull

• Recovering D.I.C Addict

Reputation: 52
• Posts: 646
• Joined: 10-March 09

## Re: Help with Car Calculator

Posted 18 July 2009 - 02:49 PM

Noe: You use the code tags like this:

Now, there are a couple of things I notice. The major thing is that when you're expecting to get user input you need to store that input into your variable.
Here for instance it should be like:
```		Console.WriteLine("Welcome to Universal Motors")
Console.Write("Enter the base price")
Console.WriteLine("")
BasePrice = CDbl(Console.ReadLine())   'Covert to double and store in BasePrice
Console.WriteLine("Engine Choice")
Console.WriteLine("S - 6 cyclinder engine")
Console.WriteLine("E - 8 cyclinder engine")
Console.WriteLine("D - Diesal Engine")
Console.WriteLine("Selection? : ")
```

And for the others:
```		Dim EngineCost As String = Console.ReadLine	'Gets user input, stores in EngineCost
Select Case EngineCost
Case ("S")
EngineCost = 150
Case ("E")
EngineCost = 475
Case ("D")
EngineCost = 750
End Select
```

The other thing is that several times you do something like:
```Dim TrimCost As StringSplitOptions
```

And I suspect what you actually want is a String. In which case the next section would follow:
```		Dim TrimCost As String = Console.ReadLine  'SplitOptions
Select Case TrimCost
Case ("V")
TrimCost = CStr(50)
Case ("C")
TrimCost = CStr(225)
Case ("L")
TrimCost = CStr(800)
End Select
```

And then:
```		Dim RadioCost As String = Console.ReadLine 'SplitOptions
Case ("R")
Case Else
End Select
```

Try that and get rid of the other Console.ReadLine statements after the Select blocks or else you'll have to press enter twice on some of them.

### #4 _HAWK_

• Master(Of Foo)

Reputation: 1162
• Posts: 4,444
• Joined: 02-July 08

## Re: Help with Car Calculator

Posted 18 July 2009 - 02:49 PM

Not much to go on here, but I would say it is because there is no code in the click event.

### #5 PsychoCoder

Reputation: 1659
• Posts: 19,853
• Joined: 26-July 07

## Re: Help with Car Calculator

Posted 18 July 2009 - 02:52 PM

Are you receiving any errors? Does this code not work that way you intended it? When asking for help there are a couple items that are vital in order for someone to properly help you:
• Post the code you're having problems with
• Post the exact error you're receiving, if you are receiving one
• If no error explain what the code is doing versus what you want it to do
• Post your question in the body of your post, not the description field

### #6 juice33

• New D.I.C Head

Reputation: 0
• Posts: 12
• Joined: 18-July 09

## Re: Help with Car Calculator

Posted 18 July 2009 - 03:06 PM

```Dim BasePrice As Decimal

Sub Main()

Console.WriteLine("Welcome to Universal Motors")
Console.Write("Enter the base price")
Console.WriteLine("")
BasePrice = CDbl(Console.ReadLine())   'Covert to double and store in BasePrice
Console.WriteLine("Engine Choice")
Console.WriteLine("S - 6 cyclinder engine")
Console.WriteLine("E - 8 cyclinder engine")
Console.WriteLine("D - Diesal Engine")
Console.WriteLine("Selection? : ")
End Sub
Dim EngineCost As String = Console.ReadLine	'Gets user input, stores in EngineCost
Select Case EngineCost
Case ("S")
EngineCost = 150
Case ("E")
EngineCost = 475
Case ("D")
EngineCost = 750
End Select

Console.WriteLine("Enter TrimChoice")
Console.WriteLine(" V - Vinyl interior trim")
Console.WriteLine(" C - Cloth interior trim")
Console.WriteLine(" L - Leather interior trim")
Console.WriteLine("Selection?   : ")
Dim TrimCost As String = Console.ReadLine  'SplitOptions
Select Case TrimCost
Case ("V")
TrimCost = CStr(50)
Case ("C")
TrimCost = CStr(225)
Case ("L")
TrimCost = CStr(800)
End Select

Console.WriteLine("R - AM/FM")
Console.WriteLine("D - CD/DVD")
Console.WriteLine("Selection?  : ")
Dim RadioCost As String = Console.ReadLine 'SplitOptions
Case ("R")
Case Else
End Select

Dim ShippingCharge, DealerCharge, SellingPrice As String
ShippingCharge = 500
DealerCharge = 175

SellingPrice = BasePrice + ShippingCharge + DealerCharge + EngineCost + TrimCost + RadioCost

Console.Write("The total selling price for your vehicle is :\$  " + SellingPrice)
Console.WriteLine("")
Console.WriteLine("... Press the [Enter] key to exit.")

End Sub

End Module

```

** Edit **

### #7 juice33

• New D.I.C Head

Reputation: 0
• Posts: 12
• Joined: 18-July 09

## Re: Help with Car Calculator

Posted 18 July 2009 - 03:18 PM

Are you receiving any errors?

"I'm Recieving no erros"

Does this code not work that way you intended it?

"This program is suppose to calculate taxable income and display the tax due for the person, but when annual income is entered, and then the calculate button is hit , no output appears

Here is a copy of the code again attached
Public Class Form1

``` Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Dim AnnualIncome, TaxDue As Double
If AnnualIncome <= 50000 Then
' 5% tax bracket
TaxDue = AnnualIncome * 0.05
ElseIf AnnualIncome >= 50000 <= 100000 Then
' 7% tax bracket
TaxDue = 2500 + ((AnnualIncome) * 0.07)
ElseIf AnnualIncome >= 100000 Then
' 9% tax bracket
TaxDue = 6000 + ((AnnualIncome) * 0.09)
TaxDue = Convert.ToDecimal(btnCalculateIncomeTax.Text)
lblTaxDue.Text = TaxDue.ToString()
End If

End Sub

Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click

End Sub

Private Sub txtTaxableincome_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtTaxableIncome.TextChanged

End Sub

Private Sub btnCalculateIncomeTax_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculateIncomeTax.Click

End Sub

Private Sub lblTaxDue_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblTaxDue.Click

End Sub

End Class
```

This post has been edited by juice33: 18 July 2009 - 03:54 PM

### #8 juice33

• New D.I.C Head

Reputation: 0
• Posts: 12
• Joined: 18-July 09

## Re: Help with Car Calculator

Posted 18 July 2009 - 03:24 PM

Cannot get the program to excute properly, every time that i fix one code the next one turn inooperable. I need help with getting this program to work as designed.

Description of program { Program that computes the purchase of thier autos by taking base price of vehicle adding various cost for differnt options and then adding shipping and dealer charges .

```Dim BasePrice As Decimal

Sub Main()

Console.WriteLine("Welcome to Universal Motors")
Console.Write("Enter the base price")
Console.WriteLine("")
BasePrice = CDbl(Console.ReadLine())   'Covert to double and store in BasePrice
Console.WriteLine("Engine Choice")
Console.WriteLine("S - 6 cyclinder engine")
Console.WriteLine("E - 8 cyclinder engine")
Console.WriteLine("D - Diesal Engine")
Console.WriteLine("Selection? : ")
End Sub
Dim EngineCost As String = Console.ReadLine	'Gets user input, stores in EngineCost
Select Case EngineCost
Case ("S")
EngineCost = 150
Case ("E")
EngineCost = 475
Case ("D")
EngineCost = 750
End Select

Console.WriteLine("Enter TrimChoice")
Console.WriteLine(" V - Vinyl interior trim")
Console.WriteLine(" C - Cloth interior trim")
Console.WriteLine(" L - Leather interior trim")
Console.WriteLine("Selection?   : ")
Dim TrimCost As String = Console.ReadLine  'SplitOptions
Select Case TrimCost
Case ("V")
TrimCost = CStr(50)
Case ("C")
TrimCost = CStr(225)
Case ("L")
TrimCost = CStr(800)
End Select

Console.WriteLine("R - AM/FM")
Console.WriteLine("D - CD/DVD")
Console.WriteLine("Selection?  : ")
Dim RadioCost As String = Console.ReadLine 'SplitOptions
Case ("R")
Case Else
End Select

Dim ShippingCharge, DealerCharge, SellingPrice As String
ShippingCharge = 500
DealerCharge = 175

SellingPrice = BasePrice + ShippingCharge + DealerCharge + EngineCost + TrimCost + RadioCost

Console.Write("The total selling price for your vehicle is :\$  " + SellingPrice)
Console.WriteLine("")
Console.WriteLine("... Press the [Enter] key to exit.")

End Sub

End Module

```

** Edit **

### #9 LoveIsNull

• Recovering D.I.C Addict

Reputation: 52
• Posts: 646
• Joined: 10-March 09

## Re: Help with Car Calculator

Posted 18 July 2009 - 03:28 PM

Again, code tags work like
Post your question in the body of the post, not the description and you did not have to make another thread for this, you could have simply made another post in your existing thread.

Now, you're expecting a string as input from the user, but the value's you are calculating with are numbers. What you need to do is something like:
```		Dim EngineCost As Integer   'Declare as integer
Select Case Console.ReadLine 'Gets user input and check it
Case ("S")
EngineCost = 150
Case ("E")
EngineCost = 475
Case ("D")
EngineCost = 750
End Select
```

And similarly for the others, using CStr wasn't required there and you definitely cannot use it here now:
```		Dim TrimCost As Integer = 0
Select Case Console.ReadLine 'TrimCost
Case ("V")
TrimCost = 50
Case ("C")
TrimCost = 225
Case ("L")
TrimCost = 800
End Select
```

What you'll probably want to do is enter a default value for your variables in case the user fails to enter the proper input, otherwise you need to check that input is valid.

### #10 juice33

• New D.I.C Head

Reputation: 0
• Posts: 12
• Joined: 18-July 09

## Re: Help with Car Calculator

Posted 18 July 2009 - 03:46 PM

Multiple errors Program will not excecute properly as designed.
Error 1 Statement cannot appear outside of a method body. 18 9 Car Price
Error 2 Statement cannot appear outside of a method body. 19 13 Car Price
Error 3 Declaration expected. 17 Car Price
Error 4 Statement cannot appear outside of a method body. 21 13 Car Price
Error 5 Declaration expected. 22 17 Car Price
Error 6 Statement cannot appear outside of a method body. 23 13 Car Price
Error 7 Declaration expected. 17 Car Price
Error 8 'End Select' must be preceded by a matching 'Select Case'.25 9 Car Price
Error 14 Statement cannot appear outside of a method body. 33 9 Car Price
Error 21 'End Select' must be preceded by a matching 'Select Case'. 40 9 Car Price
Error 32 'End Select' must be preceded by a matching 'Select Case'. 53 9 Car Price
```Module Module1
Dim BasePrice As Decimal

Sub Main()

Console.WriteLine("Welcome to Universal Motors")
Console.Write("Enter the base price")
Console.WriteLine("")
BasePrice = CDbl(Console.ReadLine())   'Covert to double and store in BasePrice
Console.WriteLine("Engine Choice")
Console.WriteLine("S - 6 cyclinder engine")
Console.WriteLine("E - 8 cyclinder engine")
Console.WriteLine("D - Diesal Engine")
Console.WriteLine("Selection? : ")
End Sub
Dim EngineCost As Integer = 0  'Declare as integer
Select Case Console.ReadLine 'Gets user input and check it
Case ("S")
EngineCost = 150
Case ("E")
EngineCost = 475
Case ("D")
EngineCost = 750
End Select

Console.WriteLine("Enter TrimChoice")
Console.WriteLine(" V - Vinyl interior trim")
Console.WriteLine(" C - Cloth interior trim")
Console.WriteLine(" L - Leather interior trim")
Console.WriteLine("Selection?   : ")
Dim TrimCost As Integer = 0 'Declare as integer
Select Case Console.ReadLine 'TrimCost
Case ("V")
TrimCost = 50
Case ("C")
TrimCost = 225
Case ("L")
TrimCost = 800
End Select

Console.WriteLine("R - AM/FM")
Console.WriteLine("D - CD/DVD")
Console.WriteLine("Selection?  : ")
Dim RadioCost As Integer = 0  'Declare as integer
Case ("R")
Case Else
End Select

Dim ShippingCharge, DealerCharge, SellingPrice As String
ShippingCharge = 500
DealerCharge = 175

SellingPrice = BasePrice + ShippingCharge + DealerCharge + EngineCost + TrimCost + RadioCost

Console.Write("The total selling price for your vehicle is :\$  " + SellingPrice)
Console.WriteLine("")
Console.WriteLine("... Press the [Enter] key to exit.")

End Sub

End Module
```

This post has been edited by juice33: 18 July 2009 - 04:14 PM

### #11 juice33

• New D.I.C Head

Reputation: 0
• Posts: 12
• Joined: 18-July 09

## Re: Help with Car Calculator

Posted 18 July 2009 - 04:15 PM

Multiple errors Program will not excecute properly as designed.
Error 1 Statement cannot appear outside of a method body. 18 9 Car Price
Error 2 Statement cannot appear outside of a method body. 19 13 Car Price
Error 3 Declaration expected. 17 Car Price
Error 4 Statement cannot appear outside of a method body. 21 13 Car Price
Error 5 Declaration expected. 22 17 Car Price
Error 6 Statement cannot appear outside of a method body. 23 13 Car Price
Error 7 Declaration expected. 17 Car Price
Error 8 'End Select' must be preceded by a matching 'Select Case'.25 9 Car Price
Error 14 Statement cannot appear outside of a method body. 33 9 Car Price
Error 21 'End Select' must be preceded by a matching 'Select Case'. 40 9 Car Price
Error 32 'End Select' must be preceded by a matching 'Select Case'. 53 9 Car Price
```Module Module1
Dim BasePrice As Decimal

Sub Main()

Console.WriteLine("Welcome to Universal Motors")
Console.Write("Enter the base price")
Console.WriteLine("")
BasePrice = CDbl(Console.ReadLine())   'Covert to double and store in BasePrice
Console.WriteLine("Engine Choice")
Console.WriteLine("S - 6 cyclinder engine")
Console.WriteLine("E - 8 cyclinder engine")
Console.WriteLine("D - Diesal Engine")
Console.WriteLine("Selection? : ")
End Sub
Dim EngineCost As Integer = 0  'Declare as integer
Select Case Console.ReadLine 'Gets user input and check it
Case ("S")
EngineCost = 150
Case ("E")
EngineCost = 475
Case ("D")
EngineCost = 750
End Select

Console.WriteLine("Enter TrimChoice")
Console.WriteLine(" V - Vinyl interior trim")
Console.WriteLine(" C - Cloth interior trim")
Console.WriteLine(" L - Leather interior trim")
Console.WriteLine("Selection?   : ")
Dim TrimCost As Integer = 0 'Declare as integer
Select Case Console.ReadLine 'TrimCost
Case ("V")
TrimCost = 50
Case ("C")
TrimCost = 225
Case ("L")
TrimCost = 800
End Select

Console.WriteLine("R - AM/FM")
Console.WriteLine("D - CD/DVD")
Console.WriteLine("Selection?  : ")
Dim RadioCost As Integer = 0  'Declare as integer
Case ("R")
Case Else
End Select

Dim ShippingCharge, DealerCharge, SellingPrice As String
ShippingCharge = 500
DealerCharge = 175

SellingPrice = BasePrice + ShippingCharge + DealerCharge + EngineCost + TrimCost + RadioCost

Console.Write("The total selling price for your vehicle is :\$  " + SellingPrice)
Console.WriteLine("")
Console.WriteLine("... Press the [Enter] key to exit.")

End Sub

End Module
```

### #12 LoveIsNull

• Recovering D.I.C Addict

Reputation: 52
• Posts: 646
• Joined: 10-March 09

## Re: Help with Car Calculator

Posted 18 July 2009 - 04:28 PM

This is freaking ridiculous. Stop making duplicate posts, or you're going to get everything but the help.
You need to take the first End Sub out of there. Your method ends at the bottom already.
```	Sub Main()

Console.WriteLine("Welcome to Universal Motors")
Console.Write("Enter the base price")
Console.WriteLine("")
BasePrice = CDbl(Console.ReadLine())   'Covert to double and store in BasePrice
Console.WriteLine("Engine Choice")
Console.WriteLine("S - 6 cyclinder engine")
Console.WriteLine("E - 8 cyclinder engine")
Console.WriteLine("D - Diesal Engine")
Console.WriteLine("Selection? : ")
End Sub	'REMOVE THIS
```

Now, any other questions why don't you ask them in one of your pre-existing threads about this exact same thing?

### #13 CamoDeveloper

• D.I.C Regular

Reputation: 20
• Posts: 250
• Joined: 12-June 09

## Re: Help with Car Calculator

Posted 18 July 2009 - 04:37 PM

It might be because you have two "End Sub"'s in there. Try adding that code inside the Main sub and delete the very last "End Sub" and see if that works.

~Camo

### #14 mark.bottomley

Reputation: 176
• Posts: 990
• Joined: 22-April 09

## Re: Help with Car Calculator

Posted 18 July 2009 - 06:57 PM

Several problems
1) move all your code to the Click routine - you are currently doing the calculations when the form is first loaded.

2) Move "lblTaxDue.Text = TaxDue.ToString()" to after the Endif - you want the output to occur after any calculation path.

3) Add some code at the start od the click routine to read some TextBox where the user has entered "AnnualIncome"

4) Post back your code after that if it doesn't work and you can't figure out what is wrong.