Have you any code?
What are the problems you have with it?
ddanbe
Senior Poster
3,829 posts since Oct 2008
Reputation Points: 2,070
Solved Threads: 661
First declare an array and put your cin in a loop to read in every digit of your bignumber. Check if it's a digit and put it in the array.
ddanbe
Senior Poster
3,829 posts since Oct 2008
Reputation Points: 2,070
Solved Threads: 661
You can read in a string like this :
string Mystr;
cout << "What's your name? ";
getline (cin, Mystr);
ddanbe
Senior Poster
3,829 posts since Oct 2008
Reputation Points: 2,070
Solved Threads: 661
int char2int(char c) {
switch(c) {
case '0': {
return 0;
}
case '1': {
return 1;
}
case '2': {
return 2;
}
case '3': {
return 3;
}
case '4': {
return 4;
}
case '5': {
return 5;
}
case '6': {
return 6;
}
case '7': {
return 7;
}
case '8': {
return 8;
}
case '9': {
return 9;
}
}
}
Take advantage of the fact that '0' through '9' are contiguous on the ASCII chart and that you can subtract characters.
int char2int(char c)
{
if (c < 48 || c > 57)
return -1; // signifies non-digit/invalid
return c - 48; // '0' is 48 in ASCII
}
VernonDozier
Posting Expert
5,527 posts since Jan 2008
Reputation Points: 2,633
Solved Threads: 711
but getline only works with letters not with numbers
strange... what if my name is U2 ?
ddanbe
Senior Poster
3,829 posts since Oct 2008
Reputation Points: 2,070
Solved Threads: 661