Problem inputing two numbers to be summed
in
Programming Questions
•
1 year ago
Hi,
I'm trying to input two numbers and have the program sum them. But I am unable to get the program to allow me to input the second number.
Does anyone know what I am doing wrong?
Thanks,
I'm trying to input two numbers and have the program sum them. But I am unable to get the program to allow me to input the second number.
Does anyone know what I am doing wrong?
Thanks,
- void setup()
{
size(500, 200);
background(255);
fill(0);
PFont f = createFont("Verdana", 16);
textFont(f);
}
void draw()
{
noLoop();
text("Type a number to be summed:", 10, 20);
}
void keyReleased()
{
int number1 = int(key) - int('0');
text(number1 + "+", 270, 20);
if (number1 != '0') {
int number2 = int(key) - int('0');
text(number2, 293, 20);
int sum = number1 + number2;
text("=", 307, 20);
text(sum, 322, 20);
}
loop();
}
1