write a c++ function called calculateSum that makes two integers as parameters and returns their sum. write a program that user input for two integers, calls the calculate sum function; and prints result.
Output
Enter the first integer: 5
Enter the second integer: 6
Sum: 11
#include <iostream>
// Function to calculate the sum of two integers
int calculateSum(int num1, int num2) {
int sum = num1 + num2;
return sum;
}
int main() {
int num1, num2;
// User input for two integers
std::cout << "Enter the first integer: ";
std::cin >> num1;
std::cout << "Enter the second integer: ";
std::cin >> num2;
// Calling the calculateSum function
int result = calculateSum(num1, num2);
// Printing the result
std::cout << "Sum: " << result << std::endl;
return 0;
}
In this code, the calculateSum function takes two integers as parameters num1 and num2 and returns their sum. The main function prompts the user to enter two integers, calls the calculateSum function with the user input, and stores the result in the result variable. Finally, it prints the result as "Sum: [result]".
I hope this helps! Let me know if you have any further questions.