declaration

I'm just a beginner and I'm writing a basic program in which I just want to print the absolute value of a number

#include <iostream>
#include <cstdlib>

int main()
{
int i;
i=5;
cout<<abs(i)<<endl;
return 0;
}

What am I not declaring here????
Nothing. It looks normal. Are you actually getting any errors?
Anyway, be sure to put that in code tags; see the articles for more on that.
And you can streamline the code
1
2
int i;
i = 5;


to the code
int i = 5;

EDIT: Waiitt.. Did you have a
using namespace std;
in there somewhere?
cout is part of the std namespace, you either need to type
std::cout <<
or put in the using directive.
Last edited on
1
2
3
4
5
6
7
8
9
10
11
#include <iostream>
using namespace std;
#include <cstdlib>

int main()
{
int i;
i=-4;
cout<<abs(i)<<endl;
return 0;
}


it work ,,,
Exactly.
Never put a using directive or declaration before any include statement. That is just asking for trouble. You are screwing with the global namespace for the <cstdlib> library.
Thanks guys!!!
I forgot to put in using namespace std;
just one small thing!!!
Topic archived. No new replies allowed.