Answers for "function return with int c++"

C++
0

function return with int c++

#include <iostream>
 
int getValueFromUser()
{
 	std::cout << "Enter an integer: ";
	int input{};
	std::cin >> input;  
 
	return input;
}
 
int main()
{
    int x{ getValueFromUser() }; // first call to getValueFromUser
    int y{ getValueFromUser() }; // second call to getValueFromUser
 
    std::cout << x << " + " << y << " = " << x + y << '\n';
 
    return 0;
}
Posted by: Guest on March-13-2021

Browse Popular Code Answers by Language