Answer to Question #244036 in C++ for ghhuh

Question #244036

Q3: 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. Q4. Explain why, given your function from Q3, getSum(1,2,3.0) is a syntax error.


1
Expert's answer
2021-09-29T04:44:49-0400
#include <iostream>
using namespace std;
int getSum(int a,int b, int c);


int main()
{
	int num1;
	int num2;
	int num3;
	int sum;


	cout<<"Enter first number: ";
	cin>>num1;
	cout<<"Enter second number: ";
	cin>>num2;
	cout<<"Enter third number: ";
	cin>>num3;


	sum=getSum(num1,num2,num3);
	
	cout<<"Sum is: "<<sum<<endl;
	
	return 0;
}
int getSum(int a,int b,int c)
{
	return (a+b+c);
}

Sample output:

Enter first number: 10

Enter second number: 20

Enter third number: 30

Sum is: 60


getSum(1,2,3.0) gives a syntax error because the function getSum() finds the sum of integers only yet 3.0 is not an integer.


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