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; } 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; +}