In: Computer Science
C++ Program:
Write a program that prompts the user for two numbers and stores them in signed integers. The program should then add those two numbers together and store the result in a signed integer and display the result. Your program should then multiply them by each other and store the result in another integer and display the result. Then do the same but with dividing the first number by the second. Display an error message to the screen if an operation has happened that does not result in a correct calculation. In other words, make sure to test your code for error cases. You can safely assume I will only give your program integers (I will give your program only decimal digits).
C++ Program:
#include <iostream>
using namespace std;
int main() {
int a,b,sum,prod,div;
cout<<"Enter first integer: ";
cin>>a;
cout<<"Enter second integer: ";
cin>>b;
sum=a+b;
cout<<"Sum of these two integers is : "<<sum<<endl;
prod=a*b;
cout<<"Sum of these two integers is : "<<prod<<endl;
try{
if(b!=0){
div=a/b;
cout<<"Div of a and b is : "<<div;
}
else
throw b;
}
catch(int b){
cout<<"Cannot divide by 0";
}
}
if you like the answer please provide a thumbs up.