Answer to Question #180764 in C++ for khairul

Question #180764

Accept two numbers and find their sum and difference. If the sum is more than the difference, display the sum otherwise display the difference


1
Expert's answer
2021-04-12T15:07:25-0400
//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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS