7 Replies - 451 Views - Last Post: 21 September 2012 - 07:42 AM Rate Topic: -----

#1 nujic  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 43
  • Joined: 25-February 12

New to VB,output keeps going to $0

Posted 20 September 2012 - 11:41 AM

Option Explicit On
Option Strict On
Module AnyDesk
	Sub Main() 	
	Dim desk As Double=200
	Dim length As Double
	Dim width As Double
	Dim wood As String=""
	Dim drawers As Double
	Dim totalCharge As Double
	Dim total As Double
	Dim order As Double
	'Customer enters order number
	System.Console.Write("Order Number: ")
	Dim orderString As String=Console.ReadLine()
	order=Convert.ToDouble(orderString)
	
	'enters length and width of given desk,if desk is over 750square inches add extra $50 to total
	System.console.write("length of desk: ")
	Dim lengthString As String=Console.ReadLine()
	length=Convert.ToDouble(lengthString)
	
	System.console.write("Enter width of desk: ")
	Dim widthString As String=Console.ReadLine()
	width=Convert.ToDouble(widthString)
		If(length*width > 750) Then
	totalCharge=+50
	End If
	
	
	'enters type of wood,2 type,mahogany or oak.pine is no extra charge
	System.console.write("Enter type of wood: ")
	Dim woodString=Console.ReadLine()
	If wood="mahogany" Then
	totalCharge=+150
	'$150 added to the total charge
	else if wood="oak" Then
	totalCharge=+125
	'$125 added to the total charge
	End If
	
	'enters how many drawers
	System.console.write("Enter number of drawers: ")
	Dim drawersString=Console.ReadLine()
	'read number of drawers, each extra drawer adds $30 to total
	If(drawers >=1) Then
	totalCharge=+(30*drawers) 
	
	End If 
	
	'based on inputs add up the total charge
	total=totalCharge+desk
	System.console.write("Total Charge: "&total.ToString("c"))
	

	
	
	
	
	


    End Sub
End Module



my total charge keeps coming as $200.00, doesn't matter what I put in,and that $200 is because the min for a desk is 200

Is This A Good Question/Topic? 0
  • +

Replies To: New to VB,output keeps going to $0

#2 maj3091  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 300
  • View blog
  • Posts: 1,772
  • Joined: 26-March 09

Re: New to VB,output keeps going to $0

Posted 20 September 2012 - 12:07 PM

Can you provide some of the numeric inputs you give.

Also, in the code below, you get a variable called WoodString and then check one called wood, so your totalcharge variable won't change at all here?
System.console.write("Enter type of wood: ")
    Dim woodString=Console.ReadLine()
    If wood="mahogany" Then
      totalCharge=+150
      '$150 added to the total charge
    else if wood="oak" Then
      totalCharge=+125
      '$125 added to the total charge
    End If



You do something similar for drawers......

Have a look at your code again.
Was This Post Helpful? 0
  • +
  • -

#3 Mina-no-Hime  Icon User is offline

  • D.I.C Head

Reputation: 98
  • View blog
  • Posts: 176
  • Joined: 23-August 12

Re: New to VB,output keeps going to $0

Posted 20 September 2012 - 12:08 PM

Look at your code - you aren't actually assigning anything to the variables that conditional (If) statements are checking. For example, with drawers:

        'enters how many drawers
        System.Console.Write("Enter number of drawers: ")
        Dim drawersString = Console.ReadLine()
        'read number of drawers, each extra drawer adds $30 to total
        If (drawers >= 1) Then    ' This is never actually assigned!
            totalCharge = +(30 * drawers)

        End If


Try adding something like this after getting the input from the user:
drawers = Double.Parse(drawersString)

Was This Post Helpful? 0
  • +
  • -

#4 nujic  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 43
  • Joined: 25-February 12

Re: New to VB,output keeps going to $0

Posted 20 September 2012 - 12:51 PM

I fixed some stuff up, but for total I only get the desk($200) plus amount of drawers, if I type mahogany or oak,it doesn't do anything still.

Module AnyDesk
	Sub Main() 	
	Dim desk As Double=200
	Dim length As Double
	Dim width As Double
	Dim wood As String
	Dim mahogany As Double=150
	Dim oak As Double=125
	Dim drawers As Double
	Dim totalCharge As Double
	Dim total As Double
	Dim order As Double
	'Customer enters order number
	System.Console.Write("Order Number: ")
	Dim orderString As String=Console.ReadLine()
	order=Convert.ToDouble(orderString)
	
	'enters length and width of given desk,if desk is over 750square inches add extra $50 to total
	System.console.write("length of desk: ")
	Dim lengthString As String=Console.ReadLine()
	length=Convert.ToDouble(lengthString)
	
	System.console.write("Enter width of desk: ")
	Dim widthString As String=Console.ReadLine()
	width=Convert.ToDouble(widthString)
		If(length*width > 750) Then
	totalCharge=+50
	End If
	
	
	'enters type of wood,2 type,mahogany or oak.pine is no extra charge
	System.console.write("Enter type of wood: ")
	wood=console.ReadLine()
	
		If wood="mahogany" Then
	totalCharge=+mahogany
	'$150 added to the total charge
		else if wood="oak" Then
	totalCharge=+oak
	'$125 added to the total charge
	End If
	
	'enters how many drawers
	System.console.write("Enter number of drawers: ")
	Dim drawersString=Console.ReadLine()
	drawers=Convert.ToDouble(drawersString)
	'read number of drawers, each extra drawer adds $30 to total
		If(drawers >=1) Then
	totalCharge=+(30*drawers) 
	
	End If 
	
	'based on inputs add up the total charge
	total=totalCharge+desk
	System.console.write("Total Charge: "&total.ToString("c"))
	

	
	
	
	
	


    End Sub
End Module




I would in put something like order#324 length#10 width#5 type of wood:mahogany drawers:3..total: comes out to $290,instead of $440
Was This Post Helpful? 0
  • +
  • -

#5 maj3091  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 300
  • View blog
  • Posts: 1,772
  • Joined: 26-March 09

Re: New to VB,output keeps going to $0

Posted 20 September 2012 - 01:00 PM

Try putting a breakpoint on the line after you have read the wood line, then step through the code and look at the route it takes. It would seem that your wood variable isn't being populated as you would expect.
Was This Post Helpful? 0
  • +
  • -

#6 nujic  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 43
  • Joined: 25-February 12

Re: New to VB,output keeps going to $0

Posted 20 September 2012 - 01:14 PM

well I do get the right answers ONLY if I put in one at a time. What I mean is,itll do the calculations for certain extra charges, but If I have several drawers AND oak,itll calculate only the drawers plus the desk,or desk width and length over 750,and put in mahogany and several drawers,itll only calculate for one thing,maybe just for the extra charge for the size of desk plus the $200(desk). lol sorry,still new to programming and only started VB few days ago
Was This Post Helpful? 0
  • +
  • -

#7 maj3091  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 300
  • View blog
  • Posts: 1,772
  • Joined: 26-March 09

Re: New to VB,output keeps going to $0

Posted 20 September 2012 - 11:54 PM

This is VB.Net code (which I don't use), but a silly question, is =+ valid, should it not be += when incrementing variables?
Was This Post Helpful? 0
  • +
  • -

#8 BobRodes  Icon User is offline

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 574
  • View blog
  • Posts: 2,989
  • Joined: 19-May 09

Re: New to VB,output keeps going to $0

Posted 21 September 2012 - 07:42 AM

I do believe that maj has hit upon the problem. totalcharge =+125 should be the same as totalcharge = 125. You don't get an error for the same reason that you don't get an error by saying totalcharge =-125. Now I can't test this theory right now, but it would be consistent with the problem the OP is experiencing.

Try turning that around so its syntax is as maj suggests; I'd bet it will solve your problem. Also, I'll move this to VB.Net.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1