Hello, New on Here and i have my first question
i have been working on this simple c calculator program. it runs ok for me until it hits the loop and repeats the option to:
Please Enter in:
+ for addition
- for subtraction
x for multiplication
/ for division
Any Key to Quit
Below is the source Code
Code:
#include <stdio.h>
/**************************************************************/
/* Main Function */
/**************************************************************/
main ()
{
char ch;
while (ch != 'q')
{
printf ("\n\nPlease Enter in:\n\n");
printf ("+ for addition\n");
printf ("- for subtraction\n");
printf ("x for multiplication\n");
printf ("/ for division\n");
printf ("Any Key to Quit\n\n\n");
scanf ("%c", &ch);
Decision(ch);
}
}
/**************************************************************/
/* Decision Function */
/**************************************************************/
Decision(ch)
{
float a,b,c;
if (ch == '+')
{
printf ("Please enter in the next two number in which you would like to add\n");
scanf ("%f", &a);
scanf ("%f", &b);
c = a + b;
printf ("Your Total is: %f\n", c);
}
else if (ch == '-')
{
printf ("Please enter in the next two number in which you would like to subtract\n");
scanf ("%f", &a);
scanf ("%f", &b);
c = a - b;
printf ("Your Total is: %f\n", c);
}
else if (ch == '*')
{
printf ("Please enter in the next two number in which you would like to multiply\n");
scanf ("%f", &a);
scanf ("%f", &b);
c = a * b;
printf ("Your Total is: %f\n", c);
}
else if (ch == '/')
{
printf ("Please enter in the next two number in which you would like to divide\n");
scanf ("%f", &a);
scanf ("%f", &b);
c = a / b;
printf ("Your Total is: %f\n", c);
}
}/***Decision End***/