You are here:

C++/C++ conversion

Advertisement


Question
Convert integers into numbers.
Example: -1025 will output to minus one zero five.
I have the minus and plus statements, I am using a switch statement for the numbers. Started with an array. Having a hard time with the rest. Can you help?

Answer
Hi I have stored the ascii character for minus. If you want to display - then you should have to store it into character array. Also, I have stored the number in reverse order. For ex -12345 = -54321
You have to reverse the array.
Here is the program.
int inum;
cout<<"enter the number";
cin>>inum;
int iquo,irem;
int iarray[20],icount=0;
for(int i=0;i<20;i++)
  iarray[i] = 0;
if(inum < 0)
{
       iarray[icount] = '-';
       icount++;
       inum = -inum;
}
while(inum >=10)
{
         irem =inum%10;
         inum = inum/10;
         iarray[icount] = irem;
         icount++;
}
iarray[icount] = inum;
icount++;
for(int i=0;i<icount;i++)
       cout<<iarray[i]<<"\n";

C++

All Answers


Answers by Expert:


Ask Experts

Volunteer


rakshitha

Expertise

Difficult questions related to C .

Experience

C ,vc ,opc ,windows CE, ActiveX

Education/Credentials
Masters in electrical engineering

©2016 About.com. All rights reserved.