Purpose of code:-
I did this mainly for sign specific calculation(+,-,/,*)using 2 numbers input ny user, then finding the greater no input by user and lastly doing square rt of that no. Is this code good enough as a clean code; if not, what changes can I implement in it?
Code:
#include <iostream>
#include <cmath>
int main() {
int num1, num2, sumoftwonumbers, subtoftwonumbers, DivOftwonumbers, MultiplyingTwoNumbers, OpSign;
// Above Line declares all the variables to be used in this calculator program
std::cout << "Type first number = " << std::endl;
std::cin >> num1;
std::cout << "Type second number = " << std::endl;
std::cin >> num2;
std::cout << std::endl; //breaks line, std:: refers to standard library
sumoftwonumbers = num1 + num2;
subtoftwonumbers = num1 - num2;
DivOftwonumbers = num1 / num2;
MultiplyingTwoNumbers = num1 * num2;
std::cout << "Type your Operation Sign: 1 for (+), 2 for (-), 3 for (/), 4 for (*),---- ";
std::cin >> OpSign;
switch(OpSign){
case 1:
std::cout << "The sum of first and second number is : " << sumoftwonumbers << std::endl;
break;
case 2:
std::cout << "The subtraction of first and second number is : " << subtoftwonumbers << std::endl;
break;
case 3:
std::cout << "The division of first and second number is : " << DivOftwonumbers << std::endl;
break;
case 4:
std::cout << "The multiplication of first and second number is : " << MultiplyingTwoNumbers << std::endl;
break;
default:
std::cout << "Invalid Operation! ";
}
// function of calculator ends here
//using if-else conditionals to display larger number
if(num1 > num2){
std::cout << "Num1 is greater"; // If Num1 is greater displays this
}else{
std::cout << "Num2 is greater"; // If Num2 is greater displays this
}
/* These blocks of codes help in addition of two numbers and
finding out the greater number from them */
std::cout << std::endl; // EMPTY LINE.
//finding square root of greater number in code below
if(num2 > num1){
std::cout << std::endl << std::endl << "Square root of greater number(num2) is = " << std::sqrt(num2);
}
else{
std::cout << "Square root of greater number(num1) is = " << std::sqrt(num1);
}
std::cout << std::endl << std::endl << "Have a good day";//This function prints simply any text between " and "
return 0;
}