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
Grault
Grault3y ago
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
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
Grault
Grault3y ago
It is also possible that I have forgotten Forms... Why are you using Forms?
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
MODiX
MODiX3y ago
use $tryparse
Kaoruko Waguri
Kaoruko WaguriOP3y ago
Class assignment
Grault
Grault3y ago
Ew.
Kaoruko Waguri
Kaoruko WaguriOP3y ago
lol I'm sooo confused right now
Grault
Grault3y ago
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
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
Kaoruko Waguri
Kaoruko WaguriOP3y ago
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
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
Grault
Grault3y ago
float.Parse would be the relevant counterpart, then.
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
Grault
Grault3y ago
Or double.Parse if you're supposed to use doubles.
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
Grault
Grault3y ago
You're going to have difficulty honoring those radio buttons without if statements. Do you have switches?
Kaoruko Waguri
Kaoruko WaguriOP3y ago
nope
Kaoruko Waguri
Kaoruko WaguriOP3y ago
an example was given to us
Grault
Grault3y ago
OK, right. So those text boxes should actually yield ints.
Kaoruko Waguri
Kaoruko WaguriOP3y ago
the double into ints?
Grault
Grault3y ago
int.Parse(textBox1.Text)
Kaoruko Waguri
Kaoruko WaguriOP3y ago
ohhhh
Grault
Grault3y ago
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.
Kaoruko Waguri
Kaoruko WaguriOP3y ago
how do I do that again? I forgot
Grault
Grault3y ago
I believe it is the Text property. In your designer.
Kaoruko Waguri
Kaoruko WaguriOP3y ago
Nope I couldn't find it wait do you mean Text?
Grault
Grault3y ago
Yep.
Kaoruko Waguri
Kaoruko WaguriOP3y ago
Grault
Grault3y ago
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.
Kaoruko Waguri
Kaoruko WaguriOP3y ago
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?
Grault
Grault3y ago
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?
Kaoruko Waguri
Kaoruko WaguriOP3y ago
converting data types is that similar?
Kaoruko Waguri
Kaoruko WaguriOP3y ago
Grault
Grault3y ago
It is... It's one way of accomplishing something that fits that description. Casting would be another, but casting a string won't work.
Kaoruko Waguri
Kaoruko WaguriOP3y ago
I'm here now right I just need to add them?
Kaoruko Waguri
Kaoruko WaguriOP3y ago
nvm
Grault
Grault3y ago
int smallCount = int.Parse(Small_One.Text)
double smallPrice = smallCount * Small;
int smallCount = int.Parse(Small_One.Text)
double smallPrice = smallCount * Small;
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.
Kaoruko Waguri
Kaoruko WaguriOP3y ago
ohhhh wait
Grault
Grault3y ago
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.
Kaoruko Waguri
Kaoruko WaguriOP3y ago
I just need to do this for the other onces right?
Grault
Grault3y ago
Yep, and then the prices get summed.
Kaoruko Waguri
Kaoruko WaguriOP3y ago
like that right?
Grault
Grault3y ago
HST must be sales tax.
Kaoruko Waguri
Kaoruko WaguriOP3y ago
yeah I think I know what to do
Grault
Grault3y ago
👍
Kaoruko Waguri
Kaoruko WaguriOP3y ago
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?
Grault
Grault3y ago
I think it will be SubtotalTxtBox.Text = subtotal.ToString();
Kaoruko Waguri
Kaoruko WaguriOP3y ago
I'm confused
Grault
Grault3y ago
Oh, OK. You don't have the subtotal yet. double subtotal = SmallPrice + MediumPrice + ...;
Kaoruko Waguri
Kaoruko WaguriOP3y ago
just add all of them? in one text
Grault
Grault3y ago
Yep. Then the grand total will just be * HST.
Kaoruko Waguri
Kaoruko WaguriOP3y ago
but wait lets say I buy 1 small and 5 large wouln't it still add the medium drink?
Grault
Grault3y ago
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.
Kaoruko Waguri
Kaoruko WaguriOP3y ago
this is the layout right now
Grault
Grault3y ago
The only way to manage this without leaning on 0 is to use if, which isn't allowed.
Kaoruko Waguri
Kaoruko WaguriOP3y ago
but wait for the timbits shouldn't I still add it? nvm
Grault
Grault3y ago
You get no timbits without if. I assume all the radio buttons will be integrated at a later point in the course.
Kaoruko Waguri
Kaoruko WaguriOP3y ago
we already learned everthing bout eadio button
Kaoruko Waguri
Kaoruko WaguriOP3y ago
Kaoruko Waguri
Kaoruko WaguriOP3y ago
it worked
Grault
Grault3y ago
How are you reacting to the radio buttons?
Kaoruko Waguri
Kaoruko WaguriOP3y ago
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
Grault
Grault3y ago
Right, so I assume only the drink size with a selected radio button should end up as part of the subtotal.
Kaoruko Waguri
Kaoruko WaguriOP3y ago
yeah
Grault
Grault3y ago
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.
Kaoruko Waguri
Kaoruko WaguriOP3y ago
I still don't know why there's a Class-Level variable in the example
Kaoruko Waguri
Kaoruko WaguriOP3y ago
Grault
Grault3y ago
I don't see one. Ah.
Kaoruko Waguri
Kaoruko WaguriOP3y ago
"double timbits;"
Grault
Grault3y ago
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.
Kaoruko Waguri
Kaoruko WaguriOP3y ago
I'm not sure what I'm doing wrong
Kaoruko Waguri
Kaoruko WaguriOP3y ago
idk why it's underlined even if I did ToString(); still underlined nvm
Grault
Grault3y ago
Everything good?
Kaoruko Waguri
Kaoruko WaguriOP3y ago
yeah I think soo I'm just having problem with such simple math to do tax right it's subtotal / HST? nvm it's *
Grault
Grault3y ago
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
Kaoruko Waguri
Kaoruko WaguriOP3y ago
so this is wrong then
Kaoruko Waguri
Kaoruko WaguriOP3y ago
my bad it's hard to see what I did I should try to clean up my code
Grault
Grault3y ago
Right, / is division and you want * multiplication. Since HST is a value between 0 and 1, multiplication by it will make your value smaller.
Kaoruko Waguri
Kaoruko WaguriOP3y ago
this is right, right?
Grault
Grault3y ago
Right, now you're showing too much precision. Moment.
Kaoruko Waguri
Kaoruko WaguriOP3y ago
what do you mean?
Grault
Grault3y ago
That HST number 0.0977430 is too precise. No one uses money that small. It should be 0.10.
Kaoruko Waguri
Kaoruko WaguriOP3y ago
yeah
Grault
Grault3y ago
Standard numeric format strings
In this article, learn to use standard numeric format strings to format common numeric types into text representations in .NET.
Grault
Grault3y ago
Apply that to all three output fields.
Grault
Grault3y ago
🙂
Kaoruko Waguri
Kaoruko WaguriOP3y ago
I'm soo sorry bout this I still don't understand
Grault
Grault3y ago
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?
Kaoruko Waguri
Kaoruko WaguriOP3y ago
Yeah
Grault
Grault3y ago
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?
Kaoruko Waguri
Kaoruko WaguriOP3y ago
....
Grault
Grault3y ago
"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.
Kaoruko Waguri
Kaoruko WaguriOP3y ago
double HST1 = (HST5 * subtotal) + 1; does that work?
Grault
Grault3y ago
No, the grouping is wrong. Moment.
Kaoruko Waguri
Kaoruko WaguriOP3y ago
Kaoruko Waguri
Kaoruko WaguriOP3y ago
that's the code right now I feel so stupid rn
Grault
Grault3y ago
HST = 0.13
subtotal = 1.33
total = ?
HST = 0.13
subtotal = 1.33
total = ?
That's the values we have so far.
HST * subtotal = 0.1729
(HST * subtotal) + 1 = 1.1729
HST * subtotal = 0.1729
(HST * subtotal) + 1 = 1.1729
That last value is less than the subtotal; that can't be right.
Kaoruko Waguri
Kaoruko WaguriOP3y ago
yeah so this was right then
Kaoruko Waguri
Kaoruko WaguriOP3y ago
Kaoruko Waguri
Kaoruko WaguriOP3y ago
don't mind Grand total kinda messed it up
Grault
Grault3y ago
HST * subtotal = 0.1729 // the tax we need to pay in addition to our purchase
HST * subtotal + subtotal = 1.5029 // the total amount of money owed
(HST * 1 + 1) * subtotal = 1.5029 // the same value, using the Distributive Property
(HST + 1) * subtotal = 1.5029 // simplified
HST * subtotal = 0.1729 // the tax we need to pay in addition to our purchase
HST * subtotal + subtotal = 1.5029 // the total amount of money owed
(HST * 1 + 1) * subtotal = 1.5029 // the same value, using the Distributive Property
(HST + 1) * subtotal = 1.5029 // simplified
Grault
Grault3y ago
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!
Kaoruko Waguri
Kaoruko WaguriOP3y ago
I'm gonna finish this tmr, Can't understand anything right now
Grault
Grault3y ago
Ping me if you have questions. I'm trying to get better at teaching.
Kaoruko Waguri
Kaoruko WaguriOP3y ago
Your teaching was really good, I'm just stupid
Grault
Grault3y ago
Communication is the responsibility of both parties, but I appreciate the sentiment.
Kaoruko Waguri
Kaoruko WaguriOP3y ago
@Grault my bad for not messaging you I've fjnishes it and I understand how to use class level
Grault
Grault3y ago
Good!
Want results from more Discord servers?
Add your server