From f78597984ee67f605c3c6e8ee41cb100c0f9baa2 Mon Sep 17 00:00:00 2001 From: PrernaRathore10 <113295862+PrernaRathore10@users.noreply.github.com> Date: Wed, 19 Oct 2022 20:27:13 +0530 Subject: [PATCH] Create calculator.cpp --- C++/calculator.cpp | 99 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 C++/calculator.cpp diff --git a/C++/calculator.cpp b/C++/calculator.cpp new file mode 100644 index 0000000..5d9d569 --- /dev/null +++ b/C++/calculator.cpp @@ -0,0 +1,99 @@ +#include +#include +using namespace std; + +float add(float a){ + float sum=a; + float b; + string c; + cout<<"Enter the next numbers to add : "; + cin>>b; + sum+=b; + cout<<"want to add more (y/n) - "; + cin>>c; + if (c=="y" or c=="Y"){ + add(sum); + return sum; + } + cout<<"Ans = "<>b; + sum-=b; + cout<<"want to subtract more (y/n) - "; + cin>>c; + if (c=="y" or c=="Y"){ + sub(sum); + return sum; + } + cout<<"Ans = "<>b; + sum*=b; + cout<<"want to multiply more (y/n) - "; + cin>>c; + if (c=="y" or c=="Y"){ + multiply(sum); + return sum; + } + cout<<"Ans = "<>b; + sum/=b; + cout<<"want to divide more (y/n) - "; + cin>>c; + if (c=="y" or c=="Y"){ + divide(sum); + return sum; + } + cout<<"Ans = "<>option; + if (option==1){ + float a; + cout<<"Enter the first number : "; + cin>>a; + add(a); + } + else if (option==2){ + float a; + cout<<"Enter the first number : "; + cin>>a; + sub(a); + } + else if (option==3){ + float a; + cout<<"Enter the first number : "; + cin>>a; + multiply(a); + } + else if (option==4){ + float a; + cout<<"Enter the first number : "; + cin>>a; + divide(a); + } + else { + cout<<"Quit.."; + break; + } + } +}