Well here is what I have so far...without the switch statement of which I was just informed.
Code:
/* C-Calculator by Matthew Nicola */
/* Mid-Term project of M. Fagan's C Programming Class */
#include <stdio.h>
#include <conio.h>
/*This is where the coding takes place:*/
#pragma argsused
int
main(void)
{
double mainval, /* The starting value for the program */
memory, /* Holds memory value for memory functions */
newval, /* This modifies the main value by operation */
exit1; /* Prevents breaking of loop */
char opr; /* Term for basic functions */
exit1 = 0;
mainval = 0.0;
memory = 0.0;
/* Calculator Introduction */
printf("Welcome to Matt Nicola's C Calculator!\n");
printf("Enter an operator and then enter the value\n");
printf("to correspond with the operator. Enjoy!\n\n");
printf("\nThe current value is 0");
printf("\nEnter the operator to begin: ");
scanf("%lf", &opr);
getchar();
while(exit1 != 1, /* Loop will not be broken until x equals 1 */
getchar()!= '\n') /* \n is terminated to prevent a bug */
{
if (opr == '+') /* Addition */
{printf("\n\nEnter a value to add to the current value: ");
scanf("%lf", &newval);
getchar();
mainval = mainval + newval;}
else if (opr == '-') /* Subtraction */
{printf("\n\nEnter a value to subtract from the current value: ");
scanf("%lf", &newval);
getchar();
mainval = mainval - newval;}
else if (opr == '*') /* Multiplication */
{printf("\n\nEnter a value to multiply the current value: ");
scanf("%lf", &newval);
getchar();
mainval = mainval * newval;}
else if (opr == '/') /* Division */
{printf("\n\nEnter a value to divide the current value: ");
scanf("%lf", &newval);
getchar();
mainval = mainval / newval;}
else if (opr == 'm') /* Activate Memory */
{printf("\n\nEnter the value for your memory: ");
scanf("%lf", &newval);
getchar();
mainval = memory;}
else if (opr == 'a') /* Memory Add-on */
{printf("\n\nEnter a value to add to the memory: ");
scanf("%lf", &newval);
getchar();
memory = memory + mainval;}
else if (opr == 'd') /* Memory Value Deduct */
{printf("\n\nEnter a value to subtract from the memory: ");
scanf("%lf", &newval);
getchar();
memory = memory - mainval;}
else if (opr == 'c') /* Clear Current Value */
{printf("\n\nThe current value has been cleared. ");
mainval = 0.0;}
else if (opr == 'e') /* Option to exit program */
{exit1 = 1;}
else if (opr == '\n')
{printf("\nERROR - Please shut down the program and debug");
printf("\n to fix the character problem.");}
else
{printf("\nThat operation is invalid.\n");}
printf("\nCurrent value is %f%8.2", mainval);
printf("\nThe value of your memory is %f%8.2", memory);
printf("\n\nEnter the operator to begin:");
scanf("%lf", &opr);
getchar();
}
return (0);
}
I guess it is doing the same thing it was in my previous edition: Skipping the loop and assuming an invalid character....wonderful. However, the switches sound like a great idea. I'll look in my text books about those.
EDIT: Darn it! I forgot to take out the newvals from the memory functions.