Why is my console doing this???

this is a copy of what the console outputs below. why is it outputting this random stuff at the end? (-1929314651 2685740)







How many vehicle's would you like to add to the inventory?: 1

Please enter the vehicle's year: 1800
Invalid year. Year must be between 1910 and 2014
Please enter the vehicle's year: 1800
Invalid year. Year must be between 1910 and 2014
Please enter the vehicle's year: 1990

Please enter the vehicle's make: jeep

Please enter the vehicle's model: wrangler

Please enter the mileage: 200
1990 jeep wrangler 200

-1929314651 2685740

Press any key to continue . . .
Last edited on
Hi,

Just a small thing, don't start a new topic if the subject is the same. Keep the original one going, otherwise we might have 20 topics about the same thing. Decide which one you are going to go with, and mark the other one as solved.

The idiom for a for loop is this:

for(ctr = 0; ctr < elementLength; ctr++) {}

On line 49, you forgot to subtract 1, hence went past the end of the array.

while(validInput2 != true)

can be written:

while(!validInput2)

See my reply to the other topic, about how to get all the info first.



got that resolved. changed this post though to make it clear what my problem is. thanks a lot, i had already caught that though and changed it to

elementLength - 1
Last edited on
i had already caught that though and changed it to

elementLength - 1


No, I am saying don't do that. Stick to the idiom I posted above - it will save you a lot of hassles in the future.
Ok. Can you tell me why I am getting the extra line though when my console outputs the final info? Am i missing a cin.ignore() or something?
Your code is gone, so that makes it difficult for others to comment.

A for loop, ends when it's end condition becomes false, so in this example:

1
2
3
4
5
6
7
8
const int SIZE = 10;
int MyArray[SIZE];

//intialise array with something

for(int a = 0; a <= SIZE; a++){
   std::cout << MyArray[a];
}


It will run 11 times, and MyArray[11] is out of bounds.

So that is why we do this:

1
2
3
4
5
6
7
8
const int SIZE = 10;
int MyArray[SIZE];

//intialise array with something

for(int a = 0; a < SIZE; a++){
   std::cout << MyArray[a];
}


Which runs 10 times - no problems.
Topic archived. No new replies allowed.