Need some help
Example: For instance, I would enter the number 5 in the textbox if I needed 5 small, but I'm trying to figure out how to do it in the code line.
110 Replies
I can't figure out what you're trying to do. At first I thought the constants were at the class level, but in a method I'm not sure what you want to do with them.
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
It is also possible that I have forgotten Forms... Why are you using Forms?
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
use
$tryparse
Class assignment
Ew.
lol
I'm sooo confused right now
I would suggest moving your constants out to class level anyway so their values can be used to populate the corresponding labels. If a price changes, you want to only need to modify one value.
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
Eugene I'm not able to use if statement my class hasn't learned it yet and the last time I used it I got in trouble
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
float.Parse
would be the relevant counterpart, then.Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
Or
double.Parse
if you're supposed to use doubles.Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
You're going to have difficulty honoring those radio buttons without if statements. Do you have switches?
nope
an example was given to us
OK, right. So those text boxes should actually yield ints.
the double into ints?
int.Parse(textBox1.Text)
ohhhh
No, each text box is a quantity of cups which will be multiplied by the corresponding price.
You should set the default value of each text box to 0 so you can parse and multiply it without an if statement.
how do I do that again? I forgot
I believe it is the Text property.
In your designer.
Nope I couldn't find it
wait do you mean Text?
Yep.
That's it. The value in the designer will populate the control initially, and the user will overwrite that value.
Now that you have a valid int value in the text box, you can call int.Parse without an error.
for the text box don't I need to convert it?
give me a second to show an example
Quick question what does Parse mean?
It means you take some text and reinterpret it with a specific meaning.
So
int.Parse("5") == 5
and double.Parse("5") == 5.0
The type of each result is different according to which Parse method you called.
Has your class covered the significance of double versus int?converting data types is that similar?
It is... It's one way of accomplishing something that fits that description. Casting would be another, but casting a string won't work.
I'm here now right I just need to add them?
nvm
smallCount * Small
multiplies an integer by a double. Because a double has more precision, the result can only fit in a double and therefore a double value is produced.ohhhh
wait
Aside: It's called double because it has twice the memory of a float. It's called a float because the number is stored in binary using floating-point format.
We almost never use floats anymore; our memory requirements have grown such that there's almost never any point in not using a double.
I just need to do this for the other onces right?
Yep, and then the prices get summed.
like that right?
HST must be sales tax.
yeah
I think I know what to do
👍
let me try to figuring it out on my own
I'll ask for help if I get stuck
@Grault Quick question I have already set the priced on the items right now I just need to figure out on how to put everything on Subtotal?
I think it will be
SubtotalTxtBox.Text = subtotal.ToString();
I'm confused
Oh, OK. You don't have the subtotal yet.
double subtotal = SmallPrice + MediumPrice + ...;
just add all of them?
in one text
Yep.
Then the grand total will just be
* HST
.but wait lets say I buy 1 small and 5 large wouln't it still add the medium drink?
Or maybe
* (1 + HST)
if HST is less than 1.
Yes, it would add the medium, but you would be buying 0 medium drinks.
So it doesn't matter.this is the layout right now
The only way to manage this without leaning on 0 is to use if, which isn't allowed.
but wait for the timbits shouldn't I still add it?
nvm
You get no timbits without if. I assume all the radio buttons will be integrated at a later point in the course.
we already learned everthing bout eadio button
it worked
How are you reacting to the radio buttons?
I didn't click the radio button for small and X-Large right and I just added the numbers it still worked
I just need to put them together
Right, so I assume only the drink size with a selected radio button should end up as part of the subtotal.
yeah
But I don't see a way to accomplish that as long as your teacher forbids conditionals.
Actually I could be a smart-ass but I doubt that would help your grade or standing with the teacher.
I still don't know why there's a Class-Level variable in the example
I don't see one.
Ah.
"double timbits;"
Yeah, that's not even the correct datatype for timbits.
It would be an int, either a count of timbits or the index of the selected radio button (0, 1, 2).
I guess it could be the price of your timbits, which is a double, but then I have a quibble with naming that variable
timbits
.
If the lesson doesn't mention that variable, I would just assume it was used in a previous revision of the document and ignore it.I'm not sure what I'm doing wrong
idk why it's underlined
even if I did ToString(); still underlined
nvm
Everything good?
yeah I think soo I'm just having problem with such simple math
to do tax right it's subtotal / HST?
nvm it's *
HST / subtotal
Since HST is less than 1 (it is intended to be the ratio to the tax portion, not to the grand total) you need to add the result of multiplication to the subtotal.
HST * subtotal + subtotal
Or equivalently: (HST + 1) * subtotal
so this is wrong then
my bad it's hard to see what I did I should try to clean up my code
Right, / is division and you want * multiplication.
Since HST is a value between 0 and 1, multiplication by it will make your value smaller.
this is right, right?
Right, now you're showing too much precision.
Moment.
what do you mean?
That HST number 0.0977430 is too precise. No one uses money that small.
It should be 0.10.
yeah
Instead of
.ToString()
use .ToString("F2")
. See here: https://learn.microsoft.com/en-us/dotnet/standard/base-types/standard-numeric-format-stringsStandard numeric format strings
In this article, learn to use standard numeric format strings to format common numeric types into text representations in .NET.
Apply that to all three output fields.
🙂
I'm soo sorry bout this I still don't understand
Note: I have no idea why both F and N formats exist. It appears to me that
.ToString("N2")
would work just as well, which is weird.
So a string is a sequence of characters, which are bytes interpreted in a standardized way. Are you clear on that?Yeah
K, so double.ToString(), or any other ToString(), produces characters to describe the object in question.
In this case it will go through each digit in the number and add the corresponding character to the string.
"F2" instructs it to only put 2 decimal digits in the string.
Better? Did I miss something?
....
"F2" does that because the people at Microsoft decided it should and documented it.
Oh, and in case the number can be described with less than two decimal digits it still gets two decimal digits; they'll just be 0.
double HST1 = (HST5 * subtotal) + 1;
does that work?
No, the grouping is wrong.
Moment.
that's the code right now
I feel so stupid rn
That's the values we have so far.
That last value is less than the subtotal; that can't be right.
yeah so this was right then
don't mind Grand total
kinda messed it up
Tutors.com
Distributive Property — Definition, Uses & Examples
What is the distributive property? Define distributive property and learn to use it in math. Review multiple distributive property examples. Watch the video!
I'm gonna finish this tmr, Can't understand anything right now
Ping me if you have questions. I'm trying to get better at teaching.
Your teaching was really good, I'm just stupid
Communication is the responsibility of both parties, but I appreciate the sentiment.
@Grault my bad for not messaging you I've fjnishes it and I understand how to use class level
Good!