Write an application that accepts from the user the wholesale cost of an item an
ID: 639351 • Letter: W
Question
Write an application that accepts from the user the wholesale cost of an item and its markup percentage. (For example, if an item's wholesale cost is $5 and its retail price is $10, then the markup is 100%)
The program should contain a function named CalculateRetail that receives the wholesale cost and markup percentage as arguments, and returns the retail price of the item.
When the user clicks the Get Retail button, the program should do the following:
- Verify that the values entered by the user for the wholesale cost and the markup percent are numeric and not negative.
- Call the CalculateRetail function
- Display the retail cost as returned from the function.
The application has to be set up like this.
Explanation / Answer
PLEASE RATE THIS ANSWER IF IT HELPED YOU. IF IT DIDN'T, DON'T RATE IT AT ALL.
---------------------------------------
Inside you CalculateRetail function, you have
Code:
You don't need to (and shouldn't) declare the arguments again inside the function. In the statement,
Code:
you have already declared decWholesale, decMarkup and ClaculateRetail as decimal numbers. If you declare these again, you are wiping out the values you got when the function was called. These variables are already declared when you come in to the function, by virtue of the fact that they are mentioned in the function declaration. All you need to do is the calculation : CalculateRetail = decWholesale *decMarkup /100. It's that simple.
Just as an illustration. Suppose you call this function from your sub using,
Code:
When you call the function, you immediately get 3 variables, all nicely declared, with 2 of them filled with appropriate values. In this context, the function declaration
Code:
is virtually equivalent to
Code:
So you see, that function declaration does all this work for you. The one thing you forgot was that it also creates a variable, with the exact name as your function, which will hold the result. The type of this variable is also defined in your function declaration, by the type following the "As" at the end. In the end, the value of this variable will be the value returned by the function, unless you specify otherwise.
Have fun.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.