Ask your own question, for FREE!
Computer Science 14 Online
OpenStudy (walters):

hi everyone.c++ help . If am having an integer eg 1234567 "input 'NOT ALWAYS THE CASE THAT I WILL HAVE 7 INTEGERS INPUT' " how can i put this integer inside an array .The problem is that the integers may varies this means that a don't have the actual length of the integer that i can use it in my array as the size, so how am I going to do this.

OpenStudy (walters):

@slotema

OpenStudy (anonymous):

So basically you want to read any size of integer from the command line? int d; cin >> d; should work, or am I missing something?

OpenStudy (walters):

int number; cin>>number; //how am i going to find the length of the number that have been entered and assign the length to a certain variable that will work as my size inside my array,.actually this is like making the dynamic array but i want at the same time to take the actual input number inside the array.

OpenStudy (anonymous):

you could calculate the length of a number by simply dividing it by 10 (or whatever your base is) until the result of the division becomes 0. E.g. 123: 123 / 10 = 12; 12 / 10 = 1; 1 / 10 = 0, so the length of the number is 3.

OpenStudy (walters):

so what if the user enters 5489766245566 how to find the length . This is more like if i am using string eg typing in reginald i can use the function myvariable.length so how to do this when i am having an integer

OpenStudy (walters):

using dynamic array i don't know how to take the input number to my array

OpenStudy (anonymous):

Do you perhaps have a bit of code that's showing your problem? 'Cause I'm not sure what you want, to be honest.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!