954,498 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Run problems.

Ok, I'm probly going to sound like a bit of an idiot, but I'm new to the programming world.

Whenever I attempt to run this program, I get a long list of error messages.

//DATATYPE.CPP
//Examples of variable declaration and
//initialization.

#include

main ()
{
//declare a constant for the square root of two
const double SQUARE_ROOT_OF_TWO = 1.414214;

int i; //declare i as an integer
long j; //j as a long integer
unsigned long k //k as an unsigned long integer
float n; //n as a floating point number

i = 3; //initialize i to 3
j = -2048111; //j to -2048111
k = 4000000001; //k to 4000000001
n = 1.887; //n to 1.887

//output constant and variables to screen
cout << SQUARE_ROOT_OF_TWO << '\n';
cout << i << '\n';
cout << j << '\n';
cout << k << '\n';
cout << n << '\n';
return 0;
}

Whenever I try to run this, I get these error messages.

In function `int main()':
expected primary-expression before "unsigned"
`k' undeclared (first use this function)
[Warning] this decimal constant is unsigned only in ISO C90
`n' undeclared (first use this function)
`cout' undeclared (first use this function)

Leontyne
Newbie Poster
1 post since Mar 2006
Reputation Points: 10
Solved Threads: 0
 

Missing a semicolon here:
unsigned long k //k as an unsigned long integer

also, either change cout to std::cout or put a 'using namespace std;' at the top after the include.

winbatch
Posting Pro in Training
466 posts since Feb 2005
Reputation Points: 68
Solved Threads: 18
 

>>Whenever I attempt to run this program,

Since you are new -- you did not run this program, but you compiled this program". If you are going to learn programming then you need to also learn programming jargon. "run a program" means the program is already compiled and you can execute it, just like you execute most other programs on your computer.

And for future reference when you post questions and code it is very helpful to everyone if you would also indicate the compiler you used, its version (if known) and the operating system you are using.

Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

main() should be int main()
there is no semicolon after unsigned long k

Just my own personal thing ... use endl in c++ and \n in c :)

cscgal
The Queen of DaniWeb
Administrator
19,422 posts since Feb 2002
Reputation Points: 1,474
Solved Threads: 230
 
main() should be int main() there is no semicolon after unsigned long k Just my own personal thing ... use endl in c++ and \n in c :)

Yes good advice, using endl in c++ also flushes the buffer however, it would also be acceptable to use '\n' as well.

Hey Dani did you get my PM? :cry:

iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
 

Ok, I'm probly going to sound like a bit of an idiot, but I'm new to the programming world.

Whenever I attempt to run this program, I get a long list of error messages.

//DATATYPE.CPP //Examples of variable declaration and //initialization.

#include

main () { //declare a constant for the square root of two const double SQUARE_ROOT_OF_TWO = 1.414214; int i; //declare i as an integer long j; //j as a long integer unsigned long k //k as an unsigned long integer float n; //n as a floating point number i = 3; //initialize i to 3 j = -2048111; //j to -2048111 k = 4000000001; //k to 4000000001 n = 1.887; //n to 1.887 //output constant and variables to screen cout << SQUARE_ROOT_OF_TWO << '\n'; cout << i << '\n'; cout << j << '\n'; cout << k << '\n'; cout << n << '\n'; return 0; }

Whenever I try to run this, I get these error messages.

In function `int main()': expected primary-expression before "unsigned" `k' undeclared (first use this function) [Warning] this decimal constant is unsigned only in ISO C90 `n' undeclared (first use this function) `cout' undeclared (first use this function)


The biggest problem with the program is this line
[Warning] this decimal constant is unsigned only in ISO C90
k= 4000000001 it will not accept if I remove one digit the program will run.
Can anyone shed some light on the subject.

olejarskiw
Newbie Poster
1 post since May 2010
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You