Calculator
Calculator
// calculator 1.0.cpp : This file contains the 'main' function. Program execution begins and ends there.
//
#include <iostream>
#include<math.h>
#include<cstdlib>
//the + function
float sum(float x) {
system("cls");
cout << " please only use 0-9 ,+ ,-, * ,/, ^, l (log)[x*log_a(b) , ! (factorial), r(root) : enter secound
number"<<endl;
float y;
_getch();
cin >> y;
system("cls");
float result;
result = y + x;
// the - function
float min(float x) {
system("cls");
cout << " please only use 0-9 ,+ ,-, * ,/, ^, l (log)[x*log_a(b) , ! (factorial), r(root) : enter secound
number" << endl << x << "-";
float y;
_getch();
cin >> y;
system("cls");
cout << " please only use 0-9 ,+ ,-, * ,/, ^, l (log)[x*log_a(b) , ! (factorial), r(root) : enter secound
number";
float result = x - y;
return x;
//the * function
float multi(float x) {
system("cls");
cout << " please only use 0-9 ,+ ,-, * ,/, ^, l (log)[x*log_a(b) , ! (factorial), r(root) : enter secound
number" << endl << x << "*";
float y;
_getch();
cin >> y;
system("cls");
return x;
//the / function
float divide(float x) {
system("cls");
cout << " please only use 0-9 ,+ ,-, * ,/, ^, l (log)[x*log_a(b) , ! (factorial), r(root) : enter secound
number" << endl << x << "/";
float y;
_getch();
cin >> y;
system("cls");
if (y == 0) {
else {
float result = x / y;
return x;
// the ^ function
float power(float x) {
system("cls");
cout << " please only use 0-9 ,+ ,-, * ,/, ^, l (log)[x*log_a(b) , ! (factorial), r(root) : enter secound
number" << endl << x << "^";
float y;
_getch();
cin >> y;
system("cls");
return x;
//logarithmic function
float b, y;
system("cls");
cout << " please only use 0-9 ,+ ,-, * ,/, ^, l (log)[x*log_a(b) , ! (factorial), r(root) : enter secound
number" << endl << x << "* log_a(b) , enter a ";
_getch();
system("cls");
cout << " please only use 0-9 ,+ ,-, * ,/, ^, l (log)[x*log_a(b) , ! (factorial), r(root) : enter secound
number" << endl << x << "* log_" << b << "(b) enter b ";
_getch();
if (y != 0 && b!=0 ) {
system("cls");
cout << x << "* log_" << b << "(" << y << ")";
// Calculate log_b(y)
_getch();
else
cout << " are you trying to make this pc blow up >:#" << endl;
cout << " wont ask " << endl << "Note : please a and b cant be equal to 0";
}
return 0;
system("cls");
cout << " please only use 0-9 ,+ ,-, * ,/, ^, l (log)[x*log_a(b) , ! (factorial), r(root) : enter secound
number" << endl ;
long fac = 1;
fac *= i;
return fac;
system("cls");
return x;
int main()
{
int loop;
loop = 1;
cout << "hello user my name is hamza shrief id:692400679 i will be your host today ;) "<<endl<< "
please only use 0 - 9, +, -, *, / , ^, l(log)[x * log_a(b), !(factorial), r(root) " << endl;
string tut;
if (loop < 2)//this make the message disaper from the secound time and onward : wow right! :O
if (tut == "y")
system("cls");
cout << "Tutorial :use me like a normal calcualtor enter the first number then the desired
opration , then the second number then hit enter for the result ;) "<<endl<<"you can start now "<<endl;
else
system("cls");
cout << "hello user please only use 0-9 ,+ ,-, * ,/, ^, l (log)[x*log_a(b) , ! (factorial), r(root) " <<
endl;
float x;
_getch();
cin >> x;
system("cls");
cout << "hello user please only use 0-9 ,+ ,-, * ,/, ^, l (log)[x*log_a(b) , ! (factorial), r(root) : select
opriation" << endl <<x ;
_getch();
string sympol;
system("cls");
if (sympol == "+") {
sum(x);
min(x);
divide(x);
multi(x);
loga(x);
int n = static_cast<int>(x); //i converted x(double ) to n(int) because factorial only accpests int
else
system("cls");
cout << "are you trying to kill me >;( dont use numbers over 13 in factorial " << endl <<
"Note:please use positve integer number thats less that 13 (due to technical essues the program can
calculate 14!)";
root(x);
else
{
cout << "are you trying to kill me >:( ? next time please use +,-,/,*,^,l,r,! ." << endl << "press enter
to end";
return 1;
string answer;
cout << endl << " :do you want to restart ?? y/n ; " ;
if (answer == "y")
loop = 2;
system("cls");
loop = 0;
else
loop = 0;
}
/*refrences note some of these i didnt implemnt and some are missing
https://www.reddit.com/r/cpp_questions/comments/ymtgom/i_recently_switched_from_c_to_c_and_t
his_code/?rdt=55329
https://cplusplus.com/forum/beginner/269832/
https://stackoverflow.com/questions/48736611/function-overload-with-c-using-vs2017
https://www.geeksforgeeks.org/how-to-convert-float-to-int-in-cpp/
https://cplusplus.com/forum/beginner/253997/
factorial
https://www.programiz.com/cpp-programming/examples/factorial
https://en.cppreference.com/w/cpp/header/type_traits
*/