declaration problems

Im trying to make a program that figures out the smallest of 3 numbers entered by the user and cant get it to work.

here is my program:
---------------------------------------------------------------------

#include "stdafx.h"
#include <iostream>
#include <math.h>
using namespace std;

int smallest(int x, int y, int z);
int small;

int main()
{
int x,y,z;
cout<<"Please enter first number: ";
cin>>x;
cout<<"Please enter second number: ";
cin>>y;
cout<<"Please enter third number: ";
cin>>z;

int smallest(int x, int y, int z);

cout<<small<<" is the smallest number of the three."<<'\n';
}

int smallest(int x, int y, int z)
{
small=x;
if(small>y)
small=y;
if(small>z)
small=z;

return small;
}
------------------------------------------------------------------

whenever i run the program it returns small as 0. and i dont know how to fix it.

int smallest(int x, int y, int z);

That isn't how you call a function. You call functions like this:
1
2
3
4
5
6
7
8
9
10
//example function
void function(int a, int b) {
   return; //doing nothing really
}

int main() {
   int z, y;
   function(z, y);
   return 0;
}


Other then that, your code looks OK, although you will probably want to return 0 at the end of main.
firedraco seems to have missed that you're not actually assigning the return value of smallest() to the 'small' variable declared in main().
Last edited on
Topic archived. No new replies allowed.