Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified simpleCalculator
Binary file not shown.
57 changes: 51 additions & 6 deletions simpleCalculator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,24 @@ double subtract(double a, double b){
return a-b;
}

double multiply(double a, double b)
{
return a * b;
}

double divide(double a, double b)
{
if (b != 0)
{
return a/b;
}
else
{
std::cout << "Invalid Divisor 0!";
}
}


int main(){
//initializing the numbers and the operator
double a = 0;
Expand All @@ -20,6 +38,8 @@ int main(){
//Print out current operations here.
std::cout << "1: Summation: +\n";
std::cout << "2: Subtract: -\n";
std::cout << "3: Multiplication: *\n";
std::cout << "4: Division: /\n";


std::cout << "Please enter the first numero\n";
Expand All @@ -31,15 +51,40 @@ int main(){

double result = 0;


if (oper == "+"){
//uncomment this to add your operation
if (oper == "*")
{
result = multiply(a,b);
std::cout << "Result to your operation:";
std::cout << a << " " << oper << " " << b << " = " << result;
}
else if(oper == "/")
{
result = divide(a,b);
if (b != 0)
{
std::cout << "Result to your operation:";
std::cout << a << " " << oper << " " << b << " = " << result;
}
}
else if (oper == "+")
{
result = sum(a,b);
std::cout << "Result to your operation:";
std::cout << a << " " << oper << " " << b << " = " << result;
}
else if(oper == "-"){
else if(oper == "-")
{
result = subtract(a,b);
std::cout << "Result to your operation:";
std::cout << a << " " << oper << " " << b << " = " << result;
}
else
{
std::cout << "Invalid Operation!";
}

std::cout << "Result to your operation:\n";
std::cout << a << " " << oper << " " << b << " = " << result;
std::cout << "\n";



}
3 changes: 3 additions & 0 deletions tempCodeRunnerFile.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
result = divide(a,b);
std::cout << "Result to your operation:";
std::cout << a << " " << oper << " " << b << " = " << result;