I have a program with an array of 500 elements. The user can input either an int or char to initialize it a value. So if the user inputs bigint bi(1642) it will assign 1 to element 0, 6 to element 1, etc. Keep in mind there are now 496 other elements that are unassigned. When I want to output this how do I tell it to stop outputting once it hits the last assigned element?
Obviously this doesn't work because it is outputting from 0-MAXINT but im not sure what else to do.
You had the magic number in a local variable 'numdigits' in the constructor (from one of your many other threads on this problem). Make that a member variable and use it in your output().
Please quit creating threads on this same subject (3 active on the 1st page alone). You're just alienating everyone by doing that. Follow the development through in a single thread and bump it when necessary.
Don't forget to reply in some manner to all who contribute.
Okay thank you, sorry I am pretty new to the site so I wasn't sure about that. So if I make 'numdigits' a member variable that will always store how many numbers are active in the array and I can use that instead of MAXINT? So essentially something like this:
Policy re. posting practices should be posted clearly on this site (and it isn't), so it's our fault too.
Will you be required only to display these bigints, or will you be adding them (overloading operator + perhaps)? If so then storing them as most significant digit 1st will cause quite a headache later, though it is most convenient right now for the purpose of displaying them.
Yes. The process is fairly easy. You get the least significant digit by using the % operator. If iVal = 4912 then:
4912%10 = 2 = value
4912/10 = 491
491%10 = 1 = value
491/10 = 49
49%10 = 9 = value
and so on until iVal == 0. Increment numdigits as you go.