Hello, i have create the below program to find the smaller number.
The program include a header file (min.h) but when i run it show me the error:
D:\C++ peiramata\proc++6.58.cpp||In function 'int main()':|
D:\C++ peiramata\proc++6.58.cpp|21|error: expected primary-expression before 'int'|
D:\C++ peiramata\proc++6.58.cpp|21|error: expected primary-expression before 'int'|
D:\C++ peiramata\proc++6.58.cpp|32|error: expected primary-expression before 'double'|
D:\C++ peiramata\proc++6.58.cpp|32|error: expected primary-expression before 'double'|
||=== Build failed: 4 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|
why is this happening?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
|
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
#include "min.h"
int main()
{
int a_int=0;
int b_int=0;
double a_double=0;
double b_double=0;
cout<<"input 2 integers "<< endl;
cout<<"a: ";
cin>>a_int;
cout<< endl;
cout<<"b: ";
cin>>b_int;
cout<<"the smaller number is: "<<minimum(int a_int, int b_int)<< endl;
cout<< endl;
cout<< endl;
cout<<"input 2 decimals "<< endl;
cout<<"a: ";
cin>>a_double;
cout<< endl;
cout<<"b: ";
cin>>b_double;
cout<<"the smallest number is: "<<minimum(double a_double, double b_double)<< endl;
}
|
and this is the header file (save as min.h) in the same folder with the above program:
template <class X>
X minimum (X a, X b)
{
X min=a;
if (b<a)
min=b;
cout<<min<< endl;
}