This function should take as it's arguments two integer values. The function should return the smaller of the two values. From main ask the user for two integer values. Pass the two values to your smallest function, then print out the returned value.

I am new to c++ and struggling with functions. I have written the following program but can not figure out where I'm going wrong please help with any explinations to help me better understand:

``````#include <iostream>
using namespace std;
int getInt();
int smallNum;
int main()
{
int z;
z = getInt();
int smallerNum = smallNum(z);
cout<<"the smaller number is "<<smallerNum<<endl;
return 0;
}
int getInt()
{

int x,y;
num=(x,y);
cout<<"please input two numbers, I will tell you which number is smaller"<<endl;
cin>>x>>y;
return x,y;
}
int smallNum
{
return (x>y?small=y:small=x);

}``````

## All 3 Replies

Is any one able to help me??

``````#include <iostream>
int smallest (int,int);

int main ()  {
int x,y;
std::cin >> x >> y;
std::cout << smallest(x,y);
}
int smallest (int x,int y)  {
return x>y ? y : x;
}``````

Thank you sooo much, I used what you helped me with but altered it to the following code below:

``````#include <iostream>
using namespace std;
int smallest (int,int);

int main ()
{
int x,y;
cout<< "Please input two integers and I will tell you which number is the smallest " << endl;
cin >> x >> y;
cout << smallest(x,y)<< " is the smaller of the two numbers you've just entered " <<endl;
}
int smallest (int x,int y)
{
return x>y?y:x;
}``````
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.