Decimal to Hex in turbo C++

Whats wrong in This Program ??
Please Help!!!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
start:
int n,i,j,a,b[100];
char opt,c[100];
cout<<"Enter the Number to be converted into Hexadecimal:";
cin>>n;
cout<<"\nThe Hexadecimal of "<<n<<" is:";
if(n%16==0)
{
cout<<"1";
}
for(i=0;n>=0;i++)
{
a=n%16;
b[i]=a;
if(b[i]==10)
{
c[i]='A';
}
if(b[i]==11)
{
c[i]='B';
}
if(b[i]==12)
{
c[i]='C';
}
if(b[i]==13)
{
c[i]='D';
}
if(b[i]==14)
{
c[i]='E';
}
if(b[i]==15)
{
c[i]='F';
}
n=n/16;
}
for(j=i-1;j>=0;j--)
{
if(b[j]>=0 && b[j]<10)
{
cout<<b[j];
}
if(b[j]==10)
{
cout<<c[j];
}
if(b[j]==11)
{
cout<<c[j];
}
if(b[j]==12)
{
cout<<c[j];
}
if(b[j]==13)
{
cout<<c[j];
}
if(b[j]==14)
{
cout<<c[j];
}
if(b[j]==15)
{
cout<<c[j];
}
}
cout<<"\nDo you want to continue:\nEnter Y for Yes\nEnter N for No\n";
cin>>opt;
if(opt=='Y'||opt=='y')
{
goto start;
}
getch();
}
Whats wrong in This Program ??

uses very old headers, has non-standard main, is badly indented and doesn't use the proper language constructs for what it should do
Now working, made some changes in it,actually am learning c++ in my college so have to use old turbo c++ (ver 3.0)


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
start:
int n,i,j,a,b[100];
char opt,c[100];
cout<<"Enter the Number to be converted into Hexadecimal:";
cin>>n;
cout<<"\nThe Hexadecimal of "<<n<<" is:";
for(i=0;n!=0;i++)
{
a=n%16;
b[i]=a;
n=n/16;
}
for(j=i-1;j>=0;j--)
{
if(b[j]==10)
{
cout<<"A";
}
else if(b[j]==11)
{
cout<<"B";
}
else if(b[j]==12)
{
cout<<"C";
}
else if(b[j]==13)
{
cout<<"D";
}
else if(b[j]==14)
{
cout<<"E";
}
else if(b[j]==15)
{
cout<<"F";
}
else
{
cout<<b[j];
}
}
cout<<"\nDo you want to continue:\nEnter Y for Yes\nEnter N for No\n";
cin>>opt;
if(opt=='Y'||opt=='y')
{
goto start;
}
getch();
}
Topic archived. No new replies allowed.