hey guys, new to daniweb here.
This is my first assignment in my first C class at school.
I'm having some trouble getting the program to work, was wondering if you folks could give me some tips. I believe I have most of the code down, I think my issue is structure/placement.
The assignment is:
Write a program that can serve as a simple calculator. This calculator keeps track of a single number (of type double) that is called result and that starts out as 0.0. Each cycle allows the user to repeatedly add, subtract, multiply, or divide by a second number. The result of one of these operations becomes the new value of result. 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 input.
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)
y
and here is what I have so far:
#include <stdio.h>
int main()
{
float result, number2;
int x;
char operation,choice,r,R;
result = 0.0;
printf("the calculator has started.\n");
do{
printf ("result is %f\n",&result);
scanf ("%c%f\n",&operation,&number2);
if (operation == '+')
printf ("%f\n", result+number2);
if (operation == '-')
printf ("%f\n", result-number2);
if (operation == '*')
printf ("%f\n", result*number2);
if (operation == '/')
printf ("%f\n", result/number2);
if (operation == 'r'||'R')
printf ("final result: %f\n",result);
printf ("do you wish to continue y/n?\n");
scanf ("%s", &choice);
if (choice =='n')
{break;}
} while (1);
return 0;
I know I'm supposed to declare a type double, but I can't seem to get any results at all when I use double. I know you guys don't do people's homework for each other, and this website has helped me a ton already. I appreciate any help I can get. Thank you.