-
August 16th, 2009, 10:36 PM
#1
newb @ c++, need help
Hey Guys,
I'm pretty new to c++ programming and what i want to do is make an int into a string (i.e. int 85 into like '8','5'). I've looked around and many people have used spintf, but how would i make it convert the 85 into a string. Cause after i convert it into a string i need to multiply it. (e.g. 8x5 = 40)
Any help would be appriciated.
Cheers
-
August 17th, 2009, 01:54 AM
#2
Re: newb @ c++, need help
Well then, you first multiply and then convert it to a string:
Code:
int v1 = 8;
int v2 = 5;
int v3 = v1 * v2;
TCHAR buffer[64];
_stprintf(buffer, _T("%d"), v3);
-
August 17th, 2009, 04:33 AM
#3
Re: newb @ c++, need help
It's not separate ints, first it is a whole number (i.e. 85) and i need to separate the whole number into 8 and 5.
Cheers
-
August 17th, 2009, 07:12 AM
#4
Re: newb @ c++, need help
Hope this isn't homework. Do you mean something like:
Code:
int myNum = 85;
int digit;
int product = 1;
while (myNum > 0)
{
digit = myNum % 10;
product = product * digit;
myNum = myNum / 10;
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|