Hi C programmers,

Can anyone help me with my 8-function calculator program? The 'do' loop creates problems (errors) in my program. I tried everything but to no success.

Thank you.

Geeth.

The program is provided below


-----------------------------------------------------------------------------------#include <stdio.h>
#include <stdlib.h>

/* This statement allows us to use the standard built in math functions */
#include <math.h>

/* Includes the separate functions (Log, Sine, Exp, Cosine, Addition.. */
/* ..Subtraction, Multiplication, Division) */
void main(void);
void do_log(float);
void do_sin(float);
void do_exp(float);
void do_cos(float);
void do_add(float, float);
void do_sub(float, float);
void do_mult(float, float);
void do_div(float, float);

/* Introduction to program */
void intro(void);

/* Instructions for user */
void instruct(void);

/* Checks whether user has entered 'equal to', '=', sign */
void equals_to(char);

/* Basic operations */
void basic(char, float, float);

/* Scientific operations */
void scientific(char, float);

/*-----------------------------------------------------------------------------*/

/* Beginning of main */
void main(void)
{
/* Input numbers */
float number1 = 9999.0, number2 = 9999.0;

/* Selects the operation, either the basic (+, -, *, /)*/
char operation = 'O';

/* Equal sign */
char equal = '^';

/* Selects the scientific operation (Sine, Cosine, Exp, Log) */
char soperation[3];

/* Introduction to My Calculator program */
intro();

/* Instructions for user */
instruct();

/* Loop for the main program */
do
{
printf(": ");

/* Enter the calculation */
scanf("%f %c %f%c", &number1, &operation, &number2, &equal);

/* These statements check if the user has entered the '=' sign */
/* Beginning of switch statement */
equals_to(equal);

/* End of switch statement */
if (number1 != 9999.0)
{

/* Beginning of switch statement */
/* Beginning of basic calculation */

basic(operation, number1, number2);

/* end of switch statement */
}
/* end of basic calculation...*/
else
{
scanf("%3s %f %c",&soperation, &number1, &equal);

/* These statements check if the user has entered the '=' sign */
/* Beginning of switch statement */
equals_to(equal);
/* End of switch statement */

/* Beginning of switch statement */
/* Beginning of scientific calculation */
scientific(soperation[0], number1);
/* end of switch statement */
}

/* End of loop */
/* Program terminates when the user has entered 'q' */
}
while (number1 != 'q');

/* End of main */
}

/*-----------------------------------------------------------------------------*/

/* Separate Functions */

/* Introduction to My Calculator program */
void intro(void)
{
printf(" My Calculator program \n");
printf(" by Geeth Asokarajan \n");
printf(" Version 1.0a, released 27/03/02 \n\n");
}

/*-----------------------------------------------------------------------------*/

/* Instructions for user */
void instruct(void)
{
printf("Please enter your calculation in either the following forms\n");
printf(" : Number1 operation Number2 = \n");
printf("or : operation number2 = \n");
}

/*-----------------------------------------------------------------------------*/

void equals_to(char equal)
{
/* These statements check if the user has entered the '=' sign */
/* Beginning of switch statement */
switch(equal)
{
case'=':
printf("Please wait! \n\n");
break;

default:
printf("Invalid operator!, Please try again!\n");
break;
}
}
/* End of switch statement */

/*-----------------------------------------------------------------------------*/

/* Begininng of switch statement */
/* Selecting appropriate basic functions */
void basic(char operation, float number1, float number2)
{

switch(operation)
{
case '+':
do_add(number1, number2);
break;
case '-':
do_sub(number1, number2);
break;
case '*':
do_mult(number1, number2);
break;
case '/':
do_div(number1, number2);
break;
default:
printf("Invalid calculation!, Please try again!\n");
break;
}
}
/* End of switch statement */

/*-----------------------------------------------------------------------------*/

/* Begininng of switch statement */
/* Selecting appropriate scientific functions */
void scientific(char soperation, float number1)
{
switch(toupper(soperation))
{
case 'Q':
printf("My Calculator program terminated!\n");
printf("Thank you for using My calculator!, Please try again!\n");
exit(0);
break;
case 'C':
do_cos(number1);
break;
case 'L':
do_log(number1);
break;
case 'S':
do_sin(number1);
break;
case 'E':
do_exp(number1);
break;
default:
printf("Invalid calculation!, Please try again!\n");
break;
}
}
/* End of switch statement */

/*-----------------------------------------------------------------------------*/

/* Beginning of Cosine function */
void do_cos(float number1)
{
printf("%f\n", cos(number1));
}
/* End of Cosine function */

/*-----------------------------------------------------------------------------*/

/* Beginning of Log function */
void do_log(float number1)
{
printf("%f\n", log(number1));
}
/* End of Log function */

/*-----------------------------------------------------------------------------*/

/* Beginning of Sine function */
void do_sin(float number1)
{
printf("%f\n", sin(number1));
}
/* End of Sine function */

/*-----------------------------------------------------------------------------*/

/* Beginning of Exp function */
void do_exp(float number1)
{
printf("%f\n", exp(number1));
}
/* End of Exp function */

/*-----------------------------------------------------------------------------*/

/* Beginning of Addition function */
void do_add(float number1, float number2)
{
printf("%f\n", number1 + number2);
}
/* End of Addition function */

/*-----------------------------------------------------------------------------*/

/* Beginning of Subtraction function */
void do_sub(float number1, float number2)
{
printf("%f\n", number1 - number2);
}
/* End of Subtraction function */

/*-----------------------------------------------------------------------------*/

/* Beginning of Multiplication function */
void do_mult(float number1, float number2)
{
printf("%f\n", number1 * number2);
}
/* End of Multiplication function */

/*-----------------------------------------------------------------------------*/

/* Beginning of Division function */
void do_div(float number1, float number2)
{
/* If the denominator is 0 then print "Division by 0 is not allowed!" */
if (number2 !=0)
printf("%f\n", number1 / number2);
else
printf("Division by 0 is not allowed!, Please try again!\n");
}
/* End of Division function */

/*-----------------------------------------------------------------------------*/