Answer to Question #161240 in C++ for Ashes

Question #161240

Write a program with a function that takes two int parameters, adds them together, then

returns the sum. The program should ask the user for two numbers, then call the function

with the numbers as arguments, and tell the user the sum.


1
Expert's answer
2021-02-09T15:29:36-0500
#include <iostream>
using namespace std;

int sum(int a, int b)
{
    return a + b;
}

int main()
{
    int a, b;
    cout<<"Enter the first number...\n";
    cin>>a;
    cout<<"Enter the second number...\n";
    cin>>b;
    
    cout<<"The sum of "<<a<<" and "<<b<<" is "<<sum(a, b);

    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