Binary2Decimal and Vise verse

Guys helps, am creating the program of c++ to calculate BinaryNumber and vise versa using switch case but i end up with so much error
Iam using the following codes

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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
  #include<iostream>

using namespace std;

int main ()

{

int input;

cout << “1. Binary to Decimal Conversion\n”;

cout << “2. Decimal to Binary Conversion\n”;

cin >> input;

switch (input)

{

case 1:

{

int num,res, i=1, dec=0;

cout << “Enter a Bianry Number: “;

cin >> num;

while (num!=0)

{

dec=dec+(num%10)*i;

i=i*2;

res=num%10;

num=num/10;

}

if(res%10=0 || res%10=1)

cout << “The Decimal Equivalent of the Binary Number is “;

cout << dec;

else

cout << “Not a Binary! Try another numbers between 0’s and 1’s only!”;

break;

}

case 2:

{

int num, i=1, bin=0;

cout << “Enter a Decimal Number: “;

cin >> num;

while (num!=0)

{

bin=bin+(num%2)*i;

i=i*10;

num=num/2;

}

cout << “The Binary Equivalent of the Decimal Number is “;

cout << bin;

break;

}

default:

cout << “That is Invalid!\n”;

break;

}

return 0;

}
Hi,

the main problem is that you are using instead of " ,

change it and see if it helps
Last edited on
closed account (48T7M4Gy)
1
2
3
4
5
if(res%10 == 0 || res%10 == 1) // <--
{ // <--
    cout << "The Decimal Equivalent of the Binary Number is ";
    cout << dec;
} // <-- 
Last edited on
Topic archived. No new replies allowed.