Accept two numbers and find their sum and difference. If the sum is more than the difference, display the sum otherwise display the difference
//C++program to find sum and difference of two numbers.
//If sum is greater than difference display sum else display difference
#include <iostream>
using namespace std;
int main(){
//Declare the variables
int number1, number2, sum, difference;
//Prompt user for the two numbers
cout<<"Enter two numbers: \n";
cout<<"First number: ";
cin>>number1;
cout<<"\n";
cout<<"Second number";
cin>>number2;
cout<<"\n";
//Calculate sum
sum = number1 + number2;
//Calculate difference
difference = number1- number2;
if(sum > difference)
{
cout<<"The sum is: "<<sum<<endl;
}
else
{
cout<<"The difference is : "<<difference<<endl;
}
return 0;
}
Comments
Leave a comment