Adding 2 large a # to a signed int.
In the book VC++ in 21 days it's giving me this demonstration to write. I tried to run it and it gives these errors
In function `int main()':
smallNumber' undeclared (first use this function)
for each function it appears in.)
Thanks for any and all the help
#include <iostream.h>
int main()
{
short int smallerNumber;
smallNumber = 32767;
cout << "small number:" << smallNumber << endl;
smallNumber++;
cout << "small number:" << smallNumber << endl;
smallNumber++;
cout << "small number:" << smallNumber << endl;
cin.get();
}
"Classes will dull your mind destroy the potential for authentic creativity"
[edited by - Noxxid on April 9, 2002 9:19:25 PM]
[edited by - Noxxid on April 9, 2002 9:20:40 PM]
"Classes will dull your mind destroy the potential for authentic creativity"
April 09, 2002 08:21 PM
smallerNumber is not declared, you do however declare a variable called smallerNumber which you do not use. Change "short int smallerNumber;" into "short int smallNumber;"
Also, so you don''t get a warning from your compiler you might want to end your program with return 0;, but it isn''t neccesary.
Ok I am totally confused at what Anonymous jus said can someone plz clarify?
"Classes will dull your mind destroy the potential for authentic creativity"
"Classes will dull your mind destroy the potential for authentic creativity"
"Classes will dull your mind destroy the potential for authentic creativity"
April 09, 2002 08:31 PM
The compiler shouldn''t warn on such a thing. main should implicitly return 0 if no other return-statement is given (according to the standard).
This is how you declared your variable:
short int smaller Number;
This is how you are using your variable
smallNumber = 32767;
These two names must match. Otherwise, you will get errors.
short int smaller Number;
This is how you are using your variable
smallNumber = 32767;
These two names must match. Otherwise, you will get errors.
ReactOS - an Open-source operating system compatible with Windows NT apps and drivers
Ohhhh I c now thanks so much I didn't notice that
[edited by - Noxxid on April 9, 2002 9:37:37 PM]
[edited by - Noxxid on April 9, 2002 9:37:37 PM]
"Classes will dull your mind destroy the potential for authentic creativity"
April 09, 2002 08:36 PM
Sorry about the confusion, a slight misspelling on my part. This is what I meant:
smallNumber is not declared, you do however declare a variable called smallerNumber which you do not use. Change "short int smallerNumber;" into "short int smallNumber;"
All variables must be declared before you use them (in C/C++), so if you want to use a variable called smallNumber you must have something similar to this:
short int smallNumber;
before any line where you use it (of course the type can be something else, but your book will explain all this).
smallNumber is not declared, you do however declare a variable called smallerNumber which you do not use. Change "short int smallerNumber;" into "short int smallNumber;"
All variables must be declared before you use them (in C/C++), so if you want to use a variable called smallNumber you must have something similar to this:
short int smallNumber;
before any line where you use it (of course the type can be something else, but your book will explain all this).
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement