Code for Calculator for PF Project
Code for Calculator for PF Project
int main() {
char choice;
float a, b, PI;
int c;
do {
cout << endl;
cout << "\t\t\t******************** Calculator ******************\n";
cout << "\t\
t-----------------------------------------------------------------------------\n";
cout << "\t\tOperations\t\tTrigonometric Functions\t\tLogarithmic
Functions\n";
cout << "\t\
t-----------------------------------------------------------------------------\n";
cout << "\n\t\t1: Division\t\t7: Sin\t\t\t13: Log\n";
cout << "\t\t2: Multiplication\t8: Cos\t\t\t14: Log with base 10\n";
cout << "\t\t3: Subtraction\t\t9: Tan\n";
cout << "\t\t4: Addition\t\t10: Inverse of Sin\n";
cout << "\t\t5: Exponent\t\t11: Inverse of Cos\n";
cout << "\t\t6: Square root\t\t12: Inverse of Tan\n";
cout << "\n\t\tEnter the function that you want to perform: ";
cin >> c;
PI = 3.14159265;
switch (c) {
case 1:
cout << "Enter 1st number: ";
cin >> a;
cout << "Enter 2nd number: ";
cin >> b;
if (b != 0)
cout << "Division = " << a / b << endl;
else
cout << "Error: Division by zero is not allowed.\n";
break;
case 2:
cout << "Enter 1st number: ";
cin >> a;
cout << "Enter 2nd number: ";
cin >> b;
cout << "Multiplication = " << a * b << endl;
break;
case 3:
cout << "Enter 1st number: ";
cin >> a;
cout << "Enter 2nd number: ";
cin >> b;
cout << "Subtraction = " << a - b << endl;
break;
case 4:
cout << "Enter 1st number: ";
cin >> a;
cout << "Enter 2nd number: ";
cin >> b;
cout << "Addition = " << a + b << endl;
break;
case 5:
cout << "Enter the base number: ";
cin >> a;
cout << "Enter the exponent: ";
cin >> b;
cout << "Exponent = " << pow(a, b) << endl;
break;
case 6:
cout << "Enter the number: ";
cin >> a;
if (a >= 0)
cout << "Square Root = " << sqrt(a) << endl;
else
cout << "Error: Cannot calculate the square root of a negative
number.\n";
break;
case 7:
cout << "Enter the angle (in radians): ";
cin >> a;
cout << "Sin = " << sin(a) << endl;
break;
case 8:
cout << "Enter the angle (in radians): ";
cin >> a;
cout << "Cos = " << cos(a) << endl;
break;
case 9:
cout << "Enter the angle (in radians): ";
cin >> a;
cout << "Tan = " << tan(a) << endl;
break;
case 10:
cout << "Enter the value (-1 to 1): ";
cin >> a;
if (a >= -1 && a <= 1)
cout << "Inverse of Sin = " << asin(a) * 180.0 / PI << "
degrees\n";
else
cout << "Error: Input out of range for arcsin.\n";
break;
case 11:
cout << "Enter the value (-1 to 1): ";
cin >> a;
if (a >= -1 && a <= 1)
cout << "Inverse of Cos = " << acos(a) * 180.0 / PI << "
degrees\n";
else
cout << "Error: Input out of range for arccos.\n";
break;
case 12:
cout << "Enter the number: ";
cin >> a;
cout << "Inverse of Tan = " << atan(a) * 180.0 / PI << " degrees\
n";
break;
case 13:
cout << "Enter the number: ";
cin >> a;
if (a > 0)
cout << "Log = " << log(a) << endl;
else
cout << "Error: Logarithm of non-positive numbers is not
defined.\n";
break;
case 14:
cout << "Enter the number: ";
cin >> a;
if (a > 0)
cout << "Log with base 10 = " << log10(a) << endl;
else
cout << "Error: Logarithm of non-positive numbers is not
defined.\n";
break;
default:
cout << "Wrong Input\n";
}
return 0;
}