The code is below... When I convert to letter then number the binary is right. When I convert the number then letter the binary messes up. Help me.
class menu
{
public:
void convert (int input);
int getValue (int input);
};
int a[8],k=1,i ;
void menu::convert(int input)
{
int d = input;
i = 0;
while (d!=0)
{
a[i]=d % 2;
d/=2;
i++;
}
cout %26lt;%26lt; "The binary code of the given number is :";
for(i=7;i%26gt;=0;i--)
cout %26lt;%26lt; a[i] ;
cout %26lt;%26lt; endl;
}
int menu::getValue(int i)
{
char ans;
int ans2;
cout %26lt;%26lt; "What letter/number?\n%26gt;%26gt;";
if (i == 2){
cin %26gt;%26gt; ans;
ans2 = int (ans);}
else{
cin %26gt;%26gt; ans2;}
return ans2;
}
int main()
{
for (;;)
{
menu user ;
int c =0, d =0;
cin %26gt;%26gt; c;
if (c %26lt;= 2)
{ d = user.getValue(c);
user.convert(d); }
else{
break;}
}
system("pause");
return 0;
}
C++ class error, it does not make sense to me at all!?
Your convert() function has few bugs.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment