From 8ae7a68f9bcc80cf52ace7039008ee64cd8ac8a2 Mon Sep 17 00:00:00 2001 From: Prateekgupta9819 <36070161+Prateekgupta9819@users.noreply.github.com> Date: Tue, 30 Oct 2018 12:59:53 +0530 Subject: [PATCH 1/2] Update calculator.cpp --- Lesson-2/solutions/calculator.cpp | 48 ++++++++++++++++++++++++------- 1 file changed, 38 insertions(+), 10 deletions(-) diff --git a/Lesson-2/solutions/calculator.cpp b/Lesson-2/solutions/calculator.cpp index 29608cc..085456e 100644 --- a/Lesson-2/solutions/calculator.cpp +++ b/Lesson-2/solutions/calculator.cpp @@ -1,12 +1,40 @@ -#include +# include +using namespace std; + int main() { - int num1, num2, num3; - std::cout << "Enter any 3 numbers" << std::endl << "Number 1: "; - std::cin >> num1; - std::cout << "Number 2 "; - std::cin >> num2; - std::cout << "Number 3 "; - std::cin >> num3; - std::cout << num1 + num2 + num3; -} \ No newline at end of file + char op; + float num1, num2; + + cout << "Enter operator either + or - or * or /: "; + cin >> op; + + cout << "Enter two operands: "; + cin >> num1 >> num2; + + switch(op) + { + case '+': + cout << num1+num2; + break; + + case '-': + cout << num1-num2; + break; + + case '*': + cout << num1*num2; + break; + + case '/': + cout << num1/num2; + break; + + default: + // If the operator is other than +, -, * or /, error message is shown + cout << "Error! operator is not correct"; + break; + } + + return 0; +} From eb476231305afe75a969406d0d4394abb3856db1 Mon Sep 17 00:00:00 2001 From: Prateekgupta9819 <36070161+Prateekgupta9819@users.noreply.github.com> Date: Tue, 30 Oct 2018 13:01:52 +0530 Subject: [PATCH 2/2] Update helloworld.cpp --- Lesson-1/examples/helloworld.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/Lesson-1/examples/helloworld.cpp b/Lesson-1/examples/helloworld.cpp index 3daff6e..f867057 100644 --- a/Lesson-1/examples/helloworld.cpp +++ b/Lesson-1/examples/helloworld.cpp @@ -4,4 +4,5 @@ int main() { //Hello World Demo cout << "Hello, World!"; + return 0; }