hello.

Public Class GasPump
    Private name As String
    Private quan As Double
    Private prequa As Boolean
    Private total As Double
    Private YN As String
    Private Const RegularPrice As Double = 13.08
    Private Const PrimePrice As Double = 13.56

    Public Sub Start()
        Readinput()
        Calctotaltopay()
        Printrecept()
    End Sub
    Private Sub Readinput()
        Console.Write("What's your name: ")
        name = Console.ReadLine()
        Console.Write("Thank you " + name)
        Console.WriteLine(vbLf & vbLf & "how much do you want: " + name)
        quan = Console.ReadLine()
        Console.Write(name("Do you want premium y/n"))
        YN = Console.ReadLine()
        Dim resp As Char = Console.ReadLine().Chars(0)
        If ((resp = "y") Or (resp = "Y")) Then
            prequa = True
        Else
            prequa = False
        End If
        Console.ReadKey()
    End Sub
    Private Sub Calctotaltopay()

    End Sub
    Private Sub Printrecept()
        Console.WriteLine("+++++++++++++++++++++++++++++++++++")
        Console.WriteLine(vbLf & vbLf & "Quality " + YN)
        Console.WriteLine("Quantity " + quan)
        Console.WriteLine("Price per unite ")
        Console.WriteLine("Sum to pay " + total)
        Console.WriteLine("+++++++++++++++++" + name("++++++++++++++++++"))
    End Sub
End Class

I get Conversion from string "Do you want premium y/n" to type 'Integer' is not valid.
and i dont know how to fix it, and yes i have Option Explicit On, Option Strict On.

And i was wondering how do you get for exempel when you type y in the question y/n and i want the PrimePrice 13.56 in to the Price per unite.

Recommended Answers

All 10 Replies

Error occur in which line?

in this line Console.Write(name("Do you want premium y/n"))

Okay. Line 21 : Console.Write(name("Do you want premium y/n")) It should be Console.Write(name + " Do you want premium y/n")

thx it was only that easy

thx it was only that easy

So it's already solved?

yes the error is but i still need help with 2 more thing that don't know how to do.

can you change so the if and else to say 13.08 instead of true false.

I try changing it prequa = True to prequa = 13.08 but it didn't work so what can you do?

I try changing it prequa = True to prequa = 13.08 but it didn't work so what can you do?

You can't. prequa type is Boolean (True or False). Prequa can't accept another value except true or false.
Make new variable as a Double or change the type of prequa from Boolean to Double.

commented: Helpfull as always.. +3

hello i have one more question

Public Class GasPump
    Private name As String
    Private quan As Double
    Private prequa As String
    Private total As Double
    Private typ As String
    Private Const RegularPrice As Double = 13.08
    Private Const PrimePrice As Double = 13.56


        Public Sub Start()
            Readinput()
            Calctotaltopay()
            Printrecept()
        End Sub
        Private Sub Readinput()
            Console.Write("What's your name: ")
            name = Console.ReadLine()
            Console.Write("Thank you " + name)
        Console.WriteLine(vbLf & vbLf & "how much do you want " + name)
            quan = Console.ReadLine()
        Console.Write(vbLf & name + " do you want premium y/n: ")
            Dim resp As Char = Console.ReadLine().Chars(0)
            If ((resp = "y") Or (resp = "Y")) Then
            prequa = PrimePrice
            Else
            prequa = RegularPrice
        End If
    End Sub
        Private Sub Calctotaltopay()
        total = quan * prequa

        End Sub
        Private Sub Printrecept()
        Console.WriteLine(vbLf & "+++++++++++++++++++++++++++++++++++")
        Console.WriteLine(vbLf & "Quality ")
            Console.WriteLine("Quantity " & quan)
        Console.WriteLine("Price per unite " & prequa)
        Console.WriteLine("Sum to pay " & total)
        Console.WriteLine(vbLf & "+++++++++++++++++++++++++++++++++++")
        End Sub

End Class

Know i have don so everything works but i still need to know how do i get regular and premium in to Console.WriteLine(vbLf & "Quality ") when the pick y or n?

You have 'typ' attribute. you can use it :

If ((resp = "y") Or (resp = "Y")) Then
    prequa = PrimePrice
    typ = "Premium"
Else
    prequa = RegularPrice
    typ = "Regular"
End If

Then change this line :

Console.WriteLine(vbLf & "Quality : " & typ)

Also : Private prequa As String it should be : Private prequa As Double total = quan * prequa --> You can't multiply Double with String. it must same type.

commented: Great +1
commented: Great +2

omg it was only that i didn't have "" when i did it.

Thx for your help

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.