Click here to Skip to main content
15,898,999 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Question on the textbook: Create a SandwichOrder application that creates a sandwich order by prompting the user for the size of the sandwich (small or large) and the fixings (lettuce, tomato, onion, mustard, mayonnaise, cheese). A small sandwich is $2.50 and a large sandwich is $4.00. Mustard and mayonnaise are free, lettuce and onion are $0.10 each, tomato is $0.25, and cheese is $0.50. The defaults should be a small sandwich with no fixings.

What I have tried:

To be specific, it's a logical error. Let's say for example, I selected large for the sandwich size and wanted tomato, and cheese as my fixings. All add up to a total of $4.75. But when I debug my application, it displays $4.50 instead... Is there something I'm doing wrong?

Const SMALL As Decimal = 2.5
        Const LARGE As Decimal = 4.0
        Const LETTUCE As Decimal = 0.1
        Const ONION As Decimal = 0.1
        Const TOMATO As Decimal = 0.25
        Const CHEESE As Decimal = 0.5
        Dim numToppings As Integer = 0
        Dim toppingsPrice As Decimal
        Dim pizzasPrice As Decimal

        If Me.chkLettuce.Checked = True Then
            numToppings += 1
            toppingsPrice = LETTUCE
        End If
        If Me.chkOnion.Checked = True Then
            numToppings += 1
            toppingsPrice = ONION
        End If
        If Me.chkTomato.Checked = True Then
            numToppings += 1
            toppingsPrice = TOMATO
        End If
        If Me.chkCheese.Checked = True Then
            numToppings += 1
            toppingsPrice = CHEESE
        End If

        If Me.radSmall.Checked = True Then
            pizzasPrice = SMALL
        End If
        If Me.radLarge.Checked = True Then
            pizzasPrice = LARGE + toppingsPrice
        End If

        Me.lbltotalprice.Text = pizzasPrice
Posted
Updated 30-Apr-18 20:36pm
v2
Comments
Patrice T 30-Apr-18 22:11pm    
"I'm receiving an error when I debug it."
May be you can tell us what is the error message and position of error ?
Member 13805710 30-Apr-18 22:20pm    
To be specific, it's a logical error. Let's say for example, I selected large for the sandwich size and wanted tomato, and cheese as my fixings. All add up to a total of $4.75. But when I debug my application, it displays $4.50 instead... Is there something I'm doing wrong?
Patrice T 30-Apr-18 22:22pm    
Use Improve question to update your question.
So that everyone can pay attention to this information.
RossMW 30-Apr-18 22:17pm    
You do not state what the error is, so its hard for us to determine what the issue is.
Of note is, you are not adding the topping costs but just stating that it is the cost of the last topping added. Not sure if that isyour intent.
Member 13805710 30-Apr-18 22:20pm    
To be specific, it's a logical error. Let's say for example, I selected large for the sandwich size and wanted tomato, and cheese as my fixings. All add up to a total of $4.75. But when I debug my application, it displays $4.50 instead... Is there something I'm doing wrong?

Topping price should be adding previous values lready selected

ie

toppingsPrice += TOMATO

etc

As I said in my comments it is presently just using the value of the last topping selected.
 
Share this answer
 
Quote:
Can anyone verify my VISUAL BASIC application?

First of all, as programmer, it is your job to verify that your code is working as expected. If something is wrong, it is your duty to find and correct bugs.

Your code says that small sandwiches do not pay toppings.

Question: What if one want double cheese ?
-----
Your code do not behave the way you expect, and you don't understand why !

There is an almost universal solution: Run your code on debugger step by step, inspect variables.
The debugger is here to show you what your code is doing and your task is to compare with what it should do.
There is no magic in the debugger, it don't know what your is supposed to do, it don't find bugs, it just help you to by showing you what is going on. When the code don't do what is expected, you are close to a bug.
To see what your code is doing: Just set a breakpoint and see your code performing, the debugger allow you to execute lines 1 by 1 and to inspect variables as it execute.

The downside of this solution:
- It is a DIY, you are the one tracking the problem and finding its roots, which lead to the solution.
The upside of this solution:
- It is also a great learning tool because it show you reality and you can see which expectation match reality.
You should find pretty quickly what is wrong.

Debugger - Wikipedia, the free encyclopedia[^]

Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^]
Basic Debugging with Visual Studio 2010 - YouTube[^]
Visual Basic / Visual Studio Video Tutorial - Basic Debugging - YouTube[^]
Visual Basic .NET programming for Beginners - Breakpoints and Debugging Tools[^]
The debugger is here to only show you what your code is doing and your task is to compare with what it should do.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900