0% found this document useful (0 votes)
12 views11 pages

Calculator

Uploaded by

hamza2006shrief
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views11 pages

Calculator

Uploaded by

hamza2006shrief
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

id :692400679 name:hamza shrief mahmoud

// calculator 1.0.cpp : This file contains the 'main' function. Program execution begins and ends there.

//

#include <iostream>

#include<math.h>

#include<cstdlib>

#include< stdlib.h >//for system cls to clear screen

#include<conio.h>//for getch it waits for input from user befoer prociding

using namespace std;

//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;

cout << x << "+";

float y;

_getch();

cin >> y;

system("cls");

cout << x << "+" << y << " ";

float result;

result = y + x;

cout << "=" << result;


return 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";

cout << x << "-" << y << " ";

float result = x - y;

cout << "=" << result;

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");

cout << x << "*" << y << " ";


float result = y * x;

cout << "=" << result;

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");

cout << x << "/" << y;

if (y == 0) {

cout << endl << "erorr x(";

else {

float result = x / y;

cout << "=" << result;

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");

cout << x << "^" << y;

float result = pow(x, y);

cout << "=" << result;

return x;

//logarithmic function

float loga(float x)//log 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 ";

// Input base and value

_getch();

cin >> b; // Base

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();

cin >> y; // Value

if (y != 0 && b!=0 ) {

system("cls");

cout << x << "* log_" << b << "(" << y << ")";

// Calculate log_b(y)

float result = x * (log(y) / log(b)); // Change of base formula

_getch();

cout << "=" << result; // Output result

else

cout << " are you trying to make this pc blow up >:#" << endl;

cout << ". . . . . ." << endl;

cout << " :( " << endl;

cout << "i ";

cout << "i ";

cout << " wont ask " << endl << "Note : please a and b cant be equal to 0";
}

return 0;

long fact(int x) { // factorial rule

system("cls");

cout << " please only use 0-9 ,+ ,-, * ,/, ^, l (log)[x*log_a(b) , ! (factorial), r(root) : enter secound
number" << endl ;

long fac = 1;

for (int i = 1; i <= x; i++) {

fac *= i;

cout << x << "!" ;

return fac;

float root(float x)//root of x

system("cls");

cout << "square root of " << x << "=";

cout << pow(x, 0.5);

return x;

int main()

{
int loop;

loop = 1;

while (loop > 0)

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

cout << "do you want a tutorial y/n : ";

cin >> tut;

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;

cin >> sympol;

system("cls");

cout << x << sympol;

if (sympol == "+") {

sum(x);

else if (sympol == "-") {

min(x);

else if (sympol == "/") {

divide(x);

else if (sympol == "*") {

multi(x);

else if (sympol == "^") {


power(x);

else if (sympol == "l")

loga(x);

else if (sympol == "!") {

if (x == static_cast<int>(x) && 14 > x > 0) {

int n = static_cast<int>(x); //i converted x(double ) to n(int) because factorial only accpests int

cout << "=" << fact(n);

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!)";

else if (sympol == "r")

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 ; " ;

cin >> answer;

if (answer == "y")

loop = 2;

system("cls");

else if (answer == "n")

cout << endl << "bye :)";

loop = 0;

else

cout << "error ending program :/ ";

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

converting float to int

https://www.geeksforgeeks.org/how-to-convert-float-to-int-in-cpp/

how to see if float can be integer

https://cplusplus.com/forum/beginner/253997/

factorial

https://www.programiz.com/cpp-programming/examples/factorial

https://en.cppreference.com/w/cpp/header/type_traits

implimentation of power function :https://www.geeksforgeeks.org/power-function-c-cpp/

*/

You might also like