The Mother Board

Motherboards.org forums. Free tech support, motherboard ID, and more.
It is currently Mon Sep 24, 2018 11:23 pm

All times are UTC - 8 hours




Post new topic Reply to topic  [ 9 posts ] 
Author Message
PostPosted: Fri Dec 10, 2004 11:29 am 
Offline
Black Belt 1st Degree
Black Belt 1st Degree

Joined: Sun May 11, 2003 8:47 pm
Posts: 1486
Location: Omaha, NE
Hello all, I know that this is kind of a basic question, but my school is really bad at teaching how to fix errors, here is the error I keep getting:

error C2065: 'number' : undeclared identifier.

How do I fixie?

_________________
Tono Sien


Love is the greatest conspiracy, by the most loving genius.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Fri Dec 10, 2004 11:32 am 
Offline
Black Belt 2nd Degree
Black Belt 2nd Degree

Joined: Mon Aug 09, 2004 7:33 pm
Posts: 2741
Location: Milwaukee - Wisconsin
dim number as int.

need to declare that sucker. :D

-Roach


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Fri Dec 10, 2004 11:34 am 
Offline
Black Belt 1st Degree
Black Belt 1st Degree

Joined: Sun May 11, 2003 8:47 pm
Posts: 1486
Location: Omaha, NE
Ok, but now I get this:

warning C4700: local variable 'number' used without having been initialized

:?

_________________
Tono Sien


Love is the greatest conspiracy, by the most loving genius.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Fri Dec 10, 2004 11:35 am 
Offline
Black Belt 2nd Degree
Black Belt 2nd Degree

Joined: Mon Aug 09, 2004 7:33 pm
Posts: 2741
Location: Milwaukee - Wisconsin
dim number as int = 0

just set it to some number so that it has something to start with.

-Roach


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Dec 16, 2004 8:35 am 
Offline
Black Belt 1st Degree
Black Belt 1st Degree

Joined: Sun May 11, 2003 8:47 pm
Posts: 1486
Location: Omaha, NE
ok, but if I'm trying to use it with something like this:

for (int j=0; j<arraysize; j++){
cout << salrange[k] << endl;
}

Then how do I get it to work? If I int it as 0 then I get a major negative number...

_________________
Tono Sien


Love is the greatest conspiracy, by the most loving genius.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Dec 16, 2004 6:36 pm 
Offline
Black Belt
Black Belt

Joined: Tue Oct 01, 2002 2:06 pm
Posts: 921
Location: Illinois
If you declare number as int, then you must assign a value to it or assign it later before using it.

If you do something like this:

int number;

cout << number;

You're going to get garbage. So if you do something like this:

int number;

for (int x = 0; x < number; x++)
{
cout << x << endl;
}

You're going to get mixed results as number is not initialized as anything yet. You will get basically garbage and an error. You need to assign the maximum you want to output.

So for example, you have the code:

for(int j = 0; j < arraysize; j++)
{
cout << salrange[k] << endl;
}

You would need to assign a number to your arraysize variable if you haven't elsewhere. Also, I don't see k as working in this scenario. Is it defined elsewhere? And if so, you're going to get the same result x amount of times (whatever you have assigned to arraysize) Basically, if k equals 5 and salrange[5] stores a wage, for example 100 dollars, you are going to print out the number 100 for each iteration of your for loop.

So let's say you have an array of 100 salaries. You would do something like this:

int arraysize = 100;

for(int j = 0; j < arraysize; j++)
{
cout << salrange[j] << endl;
}

Is that what you were asking about? I didn't fully understand your question with the example you gave.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Dec 16, 2004 6:51 pm 
Offline
Black Belt 2nd Degree
Black Belt 2nd Degree

Joined: Mon Aug 09, 2004 7:33 pm
Posts: 2741
Location: Milwaukee - Wisconsin
i think you're really close, but i "think" he's asking about the for loop variable j.

dim int j = 0

for(int j=0; j<blah; j++){
do stuff;
}

should work...i think.
or you might be able to just initialize it in the declaration.
for(dim in j=0;.......) i can't remember if c++ likes that or not....i'm starting to think it doesn't....

it's been about 2 years since i did any c++.... :?

-Roach

_________________
Lian Li Lancool First Knight Series PC-K59W
Intel Core i7-960 Bloomfield 3.2GHz
EVGA X58 FTW3 132-GT-E768-TR
EVGA GeForce GTX 1070 FTW GAMING ACX 3.0
G.SKILL Ripjaws Series 12GB (3 x 4GB)
Crucial M4 128gb SATAIII SSD x2
Crucial M4 256gb SATAIII SSD
OCZ Saber 1000 960GB Enterprise SSD
Corsair Professional Series HX850 PSU
Dell UltraSharp U2713HM 27" w/drop ceiling mount
Logitech G930 7.1 Headset
DBPOWER RGB LED Keyboard
Logitech G402 Hyperion Fury


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Dec 16, 2004 7:34 pm 
Offline
Black Belt
Black Belt

Joined: Tue Oct 01, 2002 2:06 pm
Posts: 921
Location: Illinois
I haven't worked with C++ in about 2 years as well, but I don't think he's asking about the variable j. Looking at his example, with each iteration of the for loop, j is increasing by one and in no way would result in a negative number unless j ends up exceeding the capacity of what can be stored in an int. If that is the case then he has a lot of ouput 8O

By the way, what is dim? I don't recall ever hearing that before... or I just don't remember :oops:

Or... for some reason it is not declaring correctly. I just fired up VC++ 6 to see what I got without giving an int variable a value and I also recieved a very large negative number (actually, that would be small :wink: ) Basically, when your application allocates memory for that int that you want to use, whatever is stored in that hunk of memory at the time will be displayed if you do not give a value to your variable. That shouldn't happen if you assign a value to your int variable. If it is assigning garbage, you could try a couple things. If your variable is declared in one function and you are trying to use it in another, you need to pass that variable to the function you are using it in. You can also declare that variable globally instead of locally in a function.

Hope that makes sense, kinda started rambling. :lol:


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Dec 16, 2004 7:49 pm 
Offline
Black Belt 2nd Degree
Black Belt 2nd Degree

Joined: Mon Aug 09, 2004 7:33 pm
Posts: 2741
Location: Milwaukee - Wisconsin
lol. :lol: :lol: :lol:

wow...it's been way too long since i did some c++...that, and i've been doing like 4 other languages since then....i'm mixing and matching.

nevermind on the dim statement. that's a diff lang.

my bad. :oops: somebody should have said something when i started going on it!

-Roach

_________________
Lian Li Lancool First Knight Series PC-K59W
Intel Core i7-960 Bloomfield 3.2GHz
EVGA X58 FTW3 132-GT-E768-TR
EVGA GeForce GTX 1070 FTW GAMING ACX 3.0
G.SKILL Ripjaws Series 12GB (3 x 4GB)
Crucial M4 128gb SATAIII SSD x2
Crucial M4 256gb SATAIII SSD
OCZ Saber 1000 960GB Enterprise SSD
Corsair Professional Series HX850 PSU
Dell UltraSharp U2713HM 27" w/drop ceiling mount
Logitech G930 7.1 Headset
DBPOWER RGB LED Keyboard
Logitech G402 Hyperion Fury


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC - 8 hours


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group