i changed its name..but still it is not working..and i didnt get the second part of what u said about changing a into a double rather than the int..where is that? plz help me..im going crazy with this c++..lol
I assume you want to convert a real value (with a fractional component) to the nearest integer, which is what floor(a+0.5) does.
see if this does what you require
-
#include <iostream>
-
# include<math.h>
-
-
using std::cout;
-
using std::cin;
-
using std::endl;
-
-
//declaration of function
-
double myfloor(double);
-
-
int main()
-
{
-
double a; // ** make double
-
do
-
{
-
cout<<"Rounding to the nearest integer"<<endl;
-
cout<<"Please enter a decimal btween -100 and 100 "<<endl;
-
cin>>a ;
-
myfloor(a);
-
}while(a>=-100|| a<=100);
-
cout<<"you choose to quit\a\a\a"<<endl;
-
return 0;
-
}
-
//definition of function
-
-
double myfloor (double a)
-
{
-
double b=floor(a+0.5);
-
cout<<"the floor of the number "<<a<<" is "<<b<<endl;
-
return b;
-
}
-
-
when run it gives (user input in
bold)
Rounding to the nearest integer
Please enter a decimal btween -100 and 100
67.3
the floor of the number 67.3 is 67
Rounding to the nearest integer
Please enter a decimal btween -100 and 100
67.7
the floor of the number 67.7 is 68
Rounding to the nearest integer
Please enter a decimal btween -100 and 100