fa**********@gmail.com wrote:
Please don't top post.
But, I am not supposed to use if statements,
What about while or for?
character arrays,
apstrings, or atoi in this program. That's why I can't hit on any other
way to do this.
apstrings? Is this the thing that was written a few years ago for the
AP comp sci test? Not part of standard C++.
>
On Oct 13, 9:58 am, "mlimber" <mlim...@gmail.comwrote:
>>farah727r...@gmail.com wrote:
>>>I am trying to find the numerical value of a
>>>>string
Let's consider the word string. If in fact you're supposed to do this,
then perhaps you are supposed to use the std::string class? If not,
then perhaps the problem is misleadingly worded?
Have you looked into std::istringstream?
>>>>that stores a two
digit number. I have found the numerical value of a char as:
>>>char character;
cin >character;
int number = character - 48; // Computing the numberical value of
Might
const int number = character - '0';
be better?
Shouldn't you check to see if the number is a digit before you do that?
>>>character entered
cout << "The number you entered is: " << number << endl << endl;
>>>How do I do the same and find the numerical value of a string storing 2
digits? I know a way to do this using character arrays:
for ( ; *str != '\0' ; str++)
num = (num * 10) + (*str - 48);
Where I assume that you had something like:
char str[BIGENOUGH];
How did you plan on putting decimal digits into str?
>>>But, I am not supposed to use if statements, character arrays,
apstrings, or atoi in this program.
Why not?
LR