I'm trying to compare two numbers entered by a user and use a main function to read and display the largest and smallest number. What step am I missing?
int compareNums();
int main()
{
int x = 0;
int y = 0;
cout <<"Enter a number: ";
cin >>x;
cout <<"Enter another number: ";
cin >>y;
if(x > y)
{
cout<<"Largest number: " << x << endl;
cout<<"Smallest number: " << y << endl;
}
system("pause");
return 0;
}
In your code, the text will only display if x is bigger than y. So you could add another statement similar to your '(x > y)' one, just opposite.
Also as LendraDwi mentions, your compareNums() function isn't doing anything atm. If you want to use that you could let it accept 2 numbers as parameters and call it after your input.
Callum5042 When you prototype you don't have to give it names. Though I probably would so you know what they are going to be and you can just copy/paste for the definition of the function.
I thnk if you want to call the function from if statement use bool instead of void, or if you're not using if statement inside main use int
But for now write the function first