Array Help

I need to create a method (constructor) to initialize a bigint to an int value you provide [0, maxint]. Example: bigint(128).

Here is my class:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
 #ifndef BIGINT_H
#define BIGINT_H

const int MAXINT = 500;

class bigint{
	public:
		bigint();
		bigint(int);
		bigint(char);
		void output (std::ostream& out);
		bool compare(bigint, bigint);

	private:
		int size[MAXINT];
};

#endif  


So if the user inputs (4123 for example). How would I make 4 in size[0], 1 in size [1], 2 in size [2], etc. I don't even know where to start. Im guessing I would start with a for loop but I need some help. It has to be an integer. I cant use a string yet.
Last edited on
This might work:
1
2
3
4
5
6
7
8
9
10
bigint::bigint(int input)
{
    int numdigits = log10((double)input) + 1;
    
    for (int i = numdigits-1; i >= 0; i--)
    {
        size[i] = input%10;
        intput /= 10;
    }
}
I think that may work to. I have to do the same thing with a different method just for a char instead of an int now. Is there an easier way to access individual letters of a char?
Topic archived. No new replies allowed.