hello, i'm working on a code where i have to make a calculator. i hope you guyes can check out my code and help. I would greatly appricate any help (: .
here is what i have to do,
calculator. this calculator keeps track of a
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <math.h>
double calculator ();
int main()
{
float result, finalResult, number2;
char operation, choise, i;
printf("Calculator is on.\n"); /* displays message */
result = 0.0; /* set to zero */
for(i = operation ; i != 'r' || 'R' ; )
{
printf("result = %lf\n", &result);
fflush(stdin);
scanf("%c%f\n", &operation, &number2);
if (operation == '+') /* addition */
{
result+=number2;
printf("result + %f = %f\n", number2, result);
}
if (operation == '-') /* subtraction */
{
result-=number2;
printf("result - %f = %f\n", number2, result);
}
if (operation == '*') /* multiplication */
{
result*=number2;
printf("result * %f = %f\n", number2, result);
}
if (operation == '/') /* division */
{
result/=number2;
printf("result / %f = %f\n", number2, result);
}
if (operation != '+' || '-' || '*' || '/') /* unknown operation display */
{
printf("Unknown Operator\n");
printf("Re-Enter, your last line.\n");
}
}
finalResult = result;
printf("Final result = %d\n", &finalResult);
return 0;
}
result and that starts out as 0.0. Each cycle
allows the user to rpeatedly add, subtract,
multiply, or divide by a secound number. the
calculation ends when the user enters the letter
R for "result" (either in uppercase or lowercase)
. The user is allowed to do another calculation
from the beginning as often as he or she wants.
Use the scanf for inputs.
The input format is shown in the following
sample dialog. if the user enters any
operator symbol other than +.-.*, or /,
then display message "UnknownOperatorException is"
thrown and the user is asked to reenter that line of
input..
Calculator is on.
result = 0.0
+5
result + 5.0 = 5.0
result = 5.0
*2.2
result * 2.2 = 11.0
result = 11.0
% 10
% is an unknown operation
Reenter, your last line:
* 0.1
result * 0.1 = 1.1
result = 1.1
r
Final result = 1.1
Again? (y/n)
Yes
Calculator is on
result = 0.0
+10
result + 10.0 =10.0
result = 10.0
/2
result / 2.0 = 5.0
updated result = 5.0
r
Final result = 5.0
Again? (y/n)
N
End of Program