Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
//**************************************
//
//INCLUDE files for :Basic 6 Function Ca
// lculator
//**************************************
//
#include
#include
#include
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
Terms of Agreement:
By using this code, you agree to the following terms...
1) You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for langauges that allow it) freely and with no charge.
2) You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.
3) You may link to this code from another website, but ONLY if it is not wrapped in a frame.
4) You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
#include
#include
#include
void Menu();
void CalcAdd(float first_number,float second_number);
void CalcSub(float first_number,float second_number);
void CalcMul(float first_number,float second_number);
void CalcDiv(float first_number,float second_number);
void CalcSq(float first_number);
void CalcSqrt(float first_number);
void Invalid();
void main()
{
printf("Calculator by Guy Fischman\n\n");
Menu();
}
void Menu()
{
float first_number, second_number;
int operation;
printf("********************MENU*******************\n");
printf("* 1. Add two numbers *\n");
printf("* 2. Subtract two numbers *\n");
printf("* 3. Multiply two numbers *\n");
printf("* 4. Divide two numbers *\n");
printf("* 5. Square a number *\n");
printf("* 6. Take the squart root of a number *\n");
printf("* 7. Exit this program *\n");
printf("*******************************************\n");
printf("\nChoice: ");
scanf("%d", &operation);
if (operation < 1 || operation > 7){
Invalid();
}
else{
if (operation != 7){
printf("\nEnter first number: ");
scanf("%f", &first_number);
}
if (operation != 5 && operation != 6 && operation != 7){
printf("Enter second number: ");
scanf("%f", &second_number);
}
}
switch (operation)
{
case 1:
CalcAdd(first_number,second_number);
break;
case 2:
CalcSub(first_number,second_number);
break;
case 3:
CalcMul(first_number,second_number);
break;
case 4:
CalcDiv(first_number,second_number);
break;
case 5:
CalcSq(first_number);
break;
case 6:
CalcSqrt(first_number);
break;
case 7:
exit(4);
}
printf("\n\n\n");
Menu();
}
void CalcAdd(float first_number,float second_number)
{
double result;
result = first_number + second_number;
printf("%f + %f = %f\n", first_number,second_number,result);
}
void CalcSub(float first_number,float second_number)
{
double result;
result = first_number - second_number;
printf("%f - %f = %f\n", first_number,second_number,result);
}
void CalcMul(float first_number,float second_number)
{
double result;
result = first_number * second_number;
printf("%f * %f = %f\n", first_number,second_number,result);
}
void CalcDiv(float first_number,float second_number)
{
double result;
result = first_number / second_number;
printf("%f / %f = %f\n", first_number,second_number,result);
}
void CalcSq(float first_number)
{
double result;
result = first_number * first_number;
printf("%f squared = %f\n", first_number,result);
}
void CalcSqrt(float first_number)
{
double result;
result = sqrt(first_number);
printf("Square Root of %f is %f\n", first_number,result);
}
void Invalid()
{
printf("Invalid choice entered.\n");
}