Write a full program that adds three integers. Your solution should have a function named getSum that accepts three integer parameters and returns the sum of those three integers. Your main function should call the getSum function and assigns the return value to an int variable named result that is declared inside the main function. Your program should then print out the value stored in result. Submit the code and a copy of your output.
#include <iostream>
using namespace std;
int getSum(int x,int y, int z);
int main()
{
int num1;
int num2;
int num3;
int add;
cout<<"Enter first number: ";
cin>>num1;
cout<<"Enter second number: ";
cin>>num2;
cout<<"Enter third number: ";
cin>>num3;
add=getSum(num1,num2,num3);
cout<<"Sum is: "<<add<<endl;
return 0;
}
int getSum(int x,int y,int z)
{
return (x+y+z);
}
Sample output:
Enter first number: 5
Enter second number: 7
Enter third number: 8
Sum is: 20
Comments
Leave a comment