✅ Calculator Help
Basically im making a calculator with 9 number buttons. How do i make it so that when 2 number buttons that are pressed in a row, ex. 1 and 1. Display and calculate as 11 as in eleven and not (1 + 1) as in 2
thx lmk if u need all the code so far
21 Replies
Simple. When you click numeric buttons, append that number to some variable. Perform calculations only when you press the math buttons
The exact way actual calculators work
Yes but so. If only numeric button 1 is pressed then the variable would have 1 in it. If its pressed again wouldn't the variable now have 2 inside? not 11? Help idk sorry
Oh wait uhhh
Mmm
You can use a list to store those numbers, and then calculate the actual number from that
Or use a string and later parse it
Basically what i was gonna do is store the 2 different numbers that the user wants to calculate, store tje result as an int, and then display the result in the form of a label using result.ToString();
but other than that
iii think i understand ill come back if it anything doesnt work out correctly
Alrighttt that works but how do i get the second number input after an operator button is clicked?
How about storing your current value before you clear the input?
i did label1.Text = num1.ToString();
Just to display
the number
as a string
but id need to convert it back to int if i do calculations with it
int.Parse()
and int.TryParse()
would like to introduce themselvesDid that
right after
got an error for some reason
public void button1_Click(object sender EventArgs) {
num1 = Int.Parse(num1.ToString() + "1");
label1.Text = num1.ToString();
num1 = Int.Parse();
}
no clue what im doing wrong
judging by that it's clear that you lack the fundamentals. I suggest studying those before jumping into a gui framework
Ehhhh i did some gui work on java so its fine
basically the same syntax
you clearly don't understand how methods and parameters work
what this line supposed to do ?
convert from string back to int to be able to do operations on it with num2
also gui frameworks are best used with bindings and reactivity, which is an abstraction that's hard to understand for beginners who lack basics, but it's the most efficient way to program guis
num1 is already an int
when you type "num1.ToString()" it doesn't change its type
o wait help im dumb
Did you solve @rei ?
yea all good
ty
Type "/close" then 👍