You might also want to get a better IDE. Notepad isn't particularly that good for writing code.
Printable View
You might also want to get a better IDE. Notepad isn't particularly that good for writing code.
Okay, we have very good news. The calculator has came to life! YAY!
There's just two things to take care of with this.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;
memory = 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("Enter H in operator for basic commands.\n\n");
while (exit1 == 0) {
printf("\nMEMORY: %lf", memory);
printf("\nThe current value is %lf", mainval);
printf("\n\nEnter the operator to begin: ");
scanf("%c", &opr);
switch (opr) {
case '+': /* Addition */
printf("\nEnter a value to add to the main value. ");
scanf("%lf", &newval);
mainval = mainval + newval;
break;
case '-': /* Subtraction */
printf("\nEnter a value to subtract from the main value. ");
scanf("%lf", &newval);
mainval = mainval - newval;
break;
case '*': /* Multiplication */
printf("\nEnter a value to multiply the main value. ");
scanf("%lf", &newval);
mainval = mainval * newval;
break;
case '/': /* Division */
printf("\nEnter a value to divide the main value. ");
scanf("%lf", &newval);
mainval = mainval / newval;
break;
case 'C': /* Clear */
case 'c':
mainval = 0.0;
printf("\nThe main value has been cleared.\n");
break;
case 'A': /* Add to memory */
case 'a':
printf("\nEnter a value to add to the memory. ");
scanf("%lf", &newval);
memory = memory + newval;
break;
case 'D': /* Subtract from memory */
case 'd':
printf("\nEnter a value to deduct from memory. ");
scanf("%lf", &newval);
memory = memory - newval;
break;
case 'R': /* Return the memory */
case 'r':
mainval = memory;
printf("\nMemory has returned to the main value.\n");
break;
case 'H': /* Gives basic commands to user */
case 'h':
printf("\nHELP CONTENTS\n\n");
printf("Basic operations comply to their sign.\n");
printf("c = Clear the main value.\n");
printf("a = Add value to memory.\n");
printf("d = Subtract a value from memory.\n");
printf("r = Place the memory value into the main value.\n");
printf("x = Clear the value of the memory.\n");
printf("e = Exit the program.\n\n");
break;
case 'X': /* Clear the memory */
case 'x':
memory = 0.0;
printf("\nThe memory has been cleared.\n");
break;
case 'E': /* Exit program */
case 'e':
printf("\nThank you for using the calculator. Enter any key");
printf("\nand press ENTER to exit the program.");
scanf(" ");
exit1 = 1;
break;
default:
printf("\nThat case does not comply to the operator.\n");
break;
} /* End of Switch statement. */
} /* End of While statement. */
return (0);
}
- Reduce the value to its hundredths place (o.oo)
- Take care of the bug that's making my program repeat something once everytime I enter a value.
At least it still works, but I just have one bug to take care of.
You may want to look into your use of scanf. scanf is nasty. I bet it's filling your buffer with newlines that you probably don't want.