Joshua
April 17th, 1999, 01:05 AM
Trying to get the calculator to do multiple functions like 2+2=answer*2. But it gives a very strange and large number.
This is the code for the functions, and the equal button.
case 104: GetWindowText (edit, tempStr, 104);
sscanf (tempStr, "%f", &tempVal);
num1 = tempVal;
SetWindowText (edit, " ");
if (subtotal == 0)
subtotal = num1;
else
subtotal = subtotal / num1;
count = 1;
op = '/';
break;
case 108: GetWindowText (edit, tempStr, 108);
sscanf (tempStr, "%f", &tempVal);
num1 = tempVal;
SetWindowText (edit, " ");
if (subtotal == 0)
subtotal = num1;
else
subtotal = subtotal * num1;
count = 1;
op = '*';
break;
case 112: GetWindowText (edit, tempStr, 112);
sscanf (tempStr, "%f", &tempVal);
num1 = tempVal;
SetWindowText (edit, " ");
subtotal = subtotal - num1;
count = 1;
op = '-';
break;
case 116: GetWindowText (edit, tempStr, 116);
sscanf (tempStr, "%f", &tempVal);
num1 = tempVal;
subtotal = subtotal + num1;
count = 1;
SetWindowText (edit, " ");
op = '+';
break;
case 117: GetWindowText (edit, tempStr, 117);
sscanf (tempStr, "%f", &tempVal);
switch (op)
{
case '$': num2 = tempVal;
subtotal = pow(num1, num2);
break;
case '+': num1 = tempVal;
subtotal = subtotal + num1;
count = 1;
break;
case '-': num1 = tempVal;
subtotal = subtotal - num1;
count = 1;
break;
case '*': num1 = tempVal;
if (subtotal == 0)
subtotal = num1;
else
subtotal = subtotal * num1;
count = 1;
break;
case '/': num1 = tempVal;
if (subtotal == 0)
subtotal = num1;
else
subtotal = subtotal / num1;
count = 1;
break;
}
sprintf (tempStr, "%f", subtotal);
SetWindowText (edit, tempStr);
for(i=0; i <= 100; i++)
tempStr[i]=0;
break;
This is the code for the functions, and the equal button.
case 104: GetWindowText (edit, tempStr, 104);
sscanf (tempStr, "%f", &tempVal);
num1 = tempVal;
SetWindowText (edit, " ");
if (subtotal == 0)
subtotal = num1;
else
subtotal = subtotal / num1;
count = 1;
op = '/';
break;
case 108: GetWindowText (edit, tempStr, 108);
sscanf (tempStr, "%f", &tempVal);
num1 = tempVal;
SetWindowText (edit, " ");
if (subtotal == 0)
subtotal = num1;
else
subtotal = subtotal * num1;
count = 1;
op = '*';
break;
case 112: GetWindowText (edit, tempStr, 112);
sscanf (tempStr, "%f", &tempVal);
num1 = tempVal;
SetWindowText (edit, " ");
subtotal = subtotal - num1;
count = 1;
op = '-';
break;
case 116: GetWindowText (edit, tempStr, 116);
sscanf (tempStr, "%f", &tempVal);
num1 = tempVal;
subtotal = subtotal + num1;
count = 1;
SetWindowText (edit, " ");
op = '+';
break;
case 117: GetWindowText (edit, tempStr, 117);
sscanf (tempStr, "%f", &tempVal);
switch (op)
{
case '$': num2 = tempVal;
subtotal = pow(num1, num2);
break;
case '+': num1 = tempVal;
subtotal = subtotal + num1;
count = 1;
break;
case '-': num1 = tempVal;
subtotal = subtotal - num1;
count = 1;
break;
case '*': num1 = tempVal;
if (subtotal == 0)
subtotal = num1;
else
subtotal = subtotal * num1;
count = 1;
break;
case '/': num1 = tempVal;
if (subtotal == 0)
subtotal = num1;
else
subtotal = subtotal / num1;
count = 1;
break;
}
sprintf (tempStr, "%f", subtotal);
SetWindowText (edit, tempStr);
for(i=0; i <= 100; i++)
tempStr[i]=0;
break;