I am working an assignment for my C++ class. I am trying to write a program with arrays but when I print the array out I am receiving numbers like -4.8e-299 and 7e-310. Does anyone know why I would be getting that type of number with an array. It prints out most of the array except it has those numbers in them. I cant post code up right now because I do not have wifi to do it. Thanks for any help.
But how is PERSON and person the same? One is all caps and the other is all lowercase. Can I not do that? person is initialized to 0 at the top of my code. Also in my code, I cant seem to figure out how to add each column up and add each row together before it prints out. RIght now as it is, it is adding all the numbers together. Any advise would be great.
Even if I do that change, the only thing it does is add another row and column. It still doesn't get rid of the 7e-310 in the last row. I am just trying to get rid of that last row of garbage for the total of the columns. Make sense?
You are getting garbage for one of two reasons. One, you are going out of bound at some point. Two, you are not initializing that particular index to anything.
I have not tried to run your code, but if it is not one of those reasons, I would be surprised.
<edit>
Making the changes I suggested, this is the output I get running it:
Enter sales person number (1-4), enter product number (1-5) and total sales amou
nt: 1
4
56
-1
1 2 3 4 Total
0 0 0 0 0 0 0
1 0 0 0 0 56 56
2 0 0 0 0 0 56
3 0 0 0 0 0 56
4 0 0 0 0 0 56
5 0 0 0 0 0 56
Press any key to continue . . .
<edit 2>
The reason you have too many columns should be obvious if you look at what you did for a minute.
Is it only me that is getting the garbage? I am normally getting the garbage in row 5. I don't understand why you aren't getting it. I don't want to see or use 0 in my code. That is why I started at 1 for I and j.
I know that arrays start at 0. But for my assignment it is to print out 1-4 and a total for the columns and 1 - 5 for the rows. That si why I don't want to print out the 0. But even when I make the changes you suggested, I still get the weird -2.6e-29 numbers in the last row. I don't know how or what I am doing wrong. I am using XCode to write and compile my program. Could there be something wrong with XCode?
That should not matter. The problem is you wanting to avoid something that every programmer has to deal with. It is not hard to add 1 to 0 in your code when needed, trying to work around it just creates problems, as you noticed.
I really do not understand what your final output should be, or input, for that matter, but I am not going to write it for you either. I changed it to 5 rows and 4 columns in that last printout if that helps any. As long as you try to avoid using 0 for indexes, you will spend more time trying to make it work than anything else, you are pushing a boulder uphill.
Your right. I think I figured it out. I was stupid and even after your suggestion to change the for (i =1; i<= PRODUCT; ++i) I was still looking at your code and saw for (i =0; i< PRODUCT; ++i) I didn't notice that I should of taken the = out. A dumb mistake on my part. Thank you for your help.
So essentially what I was doing was printing out the element of the array that I was not even trying to use. SO what you said about not initializing an element is what was happening. I just did not realize how I was doing it until now. Thanks again.