Here is my solution:
Code:
#include <iostream.h>
#include "apvector.h"
int getlength(int sent);
int getmember(int sent, int member);
int power(int num, int pow);
void outmoney(int nonmoney);
int main()
{
outmoney(321231);
outmoney(231);
outmoney(897668);
outmoney(13594);
outmoney(1);
outmoney(12);
return 0;
}
int getlength(int sent)
{
int count=1;
while(sent>=10)
{
sent/=10;
++count;
}
return count;
}
int getmember(int sent, int member)
{
int sentlength, sent2, temp1, temp2, converted;
sentlength=1;
sent2=sent;
while(sent2>=10)
{
sent2/=10;
++sentlength;
}
temp1=power(10,sentlength-member);
temp2=power(10,sentlength-(member+1));
converted=(sent%(temp1))-(sent%(temp2));
while(converted>=10)
converted/=10;
return converted;
}
int power(int num, int pow)
{
if(pow==0)
return 1;
int returned;
returned=num;
while(pow>1)
{
returned*=num;
--pow;
}
return returned;
}
void outmoney(int nonmoney)
{
int length=getlength(nonmoney);
if(length==1)
cout<<char(156)<<'.'<<0<<nonmoney;
else
{
apvector<int> moneyarray(length);
for(int f1=0;f1<length;++f1)
moneyarray[f1]=getmember(nonmoney,f1);
cout<<char(156);
for(int f2=0;f2<length;++f2)
{
if(f2==length-2)
cout<<'.'<<moneyarray[f2];
else
cout<<moneyarray[f2];
}
}
cout<<endl;
}
I wrote the above funtions for previous programs and they have been very usefull.
The functions getlength and getmember are used to typecast ints into arrays (or vectors). getlength returns the length of an int as if it were an array of ints less than 10. getmember returns the member specified of your virtual array of ints less than 10 (or any int . I used vectors in my example because I can't stand how unflexable plain arrays are.
You like?
()Q()