|
The Oblivious One
Join Date: May 2005
Location: Ontario, Canada
Posts: 644
Rep Power: 4 
|
simple calculator
Okie dokie, time to show off my beginner C skills :p
I made this calculator using simple commands, and basic C language.
Using the functions and commands that I used, could you recommend any changes?
/*This is a calculator program. It may be edited, but the original author must be mentioned. *
*it was written on 2005-06-23 by Jesse H-K */
#include <stdio.h>
#define FALSE 0
#define TRUE !FALSE
int main()
{
float num1, num2, total;
char oper;
int trigger, choice, done;
done = FALSE;
while(!done)
{
printf("\n\n\n\t\t~~ C A L C U L A T O R ~~");
printf("\n\nThis will calculate the answer to a SIMPLE math question (eg: 2 * 3)");
printf("\nOperators are as follows:");
putchar('\n');
putchar('\n');
puts(" / = divide ");
puts(" * = multiply ");
puts(" + = add");
puts(" - = subtract");
putchar('\n');
printf("Enter the first number: ");
scanf("%f", &num1);
fflush(stdin);
printf("Enter the operator: "); /* enter +, -, etc */
oper = getchar();
fflush(stdin);
printf("Enter the second number: ");
scanf("%f", &num2);
if(oper == '+')
{
total = num1+num2;
printf("\n\n%.2f + %.2f = %.2f",num1, num2, total);
}
else if(oper == '-')
{
total = num1-num2;
printf("\n\n%.2f - %.2f = %.2f", num1, num2, total);
putchar('\n');
}
else if(oper == '*')
{
total = num1 * num2;
printf("\n\n%.2f * %.2f = %.2f", num1, num2, total);
putchar('\n');
}
else if(oper == '/')
{
total = num1 / num2;
printf("\n\n%.2f / %.2f = %.2f", num1, num2, total);
putchar('\n');
}
else
{
printf("Follow the directions directions next time");
}
putchar('\n');
putchar('\n');
printf("Repeat?\n\n");
puts("no = 1");
puts("yes = 2");
fflush(stdin);
printf("\tEnter choice: ");
scanf("%d", &choice);
switch(choice)
{
case 1:
done = TRUE;
break;
case 2:
break;
}
}
fflush(stdin);
return(0);
} /* end of program */
comments? 
Last edited by Jessehk; May 24th, 2005 at 9:35 PM.
|