You're giving new[] a value of -1, and it's interpreting it as 4294967295. |
Alright, so when I declared it:
int* z = new int[x];
it actually takes the form of an unsigned integer? If that's the case I'm assuming I can't declare it as a signed integer. Is that just how that works?
Although an idea just occurred to me. Each memory cell is one byte, right? Is there a way to take the users input and convert it to a string of bits/bytes and assign these to the the dynamic memory? Then I could perform binary math on that string. I guess the tricky part would be converting the large string of bytes back into decimals in a way the computer will understand. Maybe as a character string of the digits?
Though i do have a suggestion, you're going to want to accommodate for the idiot who tries to enter letters (like me!) |
With regards to you, I thought about that. I actually tried entering a number last night and realized the error. I was kinda hoping it would just convert it to its integer form lol. Is there a way to only accept certain keyboard entries into the console?
Actually, another though, do you think this should allow for only numerical entries?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
int ii = 0;
char b[32];
cout << "Input: ";
while(true)
{
b[ii] = getch();
while (b[ii] <'0' || b[ii] > '9')
{
b[ii] = getch();
if (b[ii] = /*enter*/)
{
break;
}
}
cout << b[ii];
}
|
I just threw this together in a few minutes. I'm sure there's a better way but should this method work? I'm looking for a proof of method right now.
Thanks for your help guys.