#include <iostream>
#include <fstream>
#include <sstream>
#include <cstdlib>
using namespace std;
int dectoint (string st);
int hextoint (string st);
int bintoint (string st);
string inttobin (int n);
//string inttohex (int n);
//string inttodec (int n);
int main()
{
string st;
cout<< "Enter a number in dec,hex,or binary: \n";
getline(cin,st);
if (st[0]=='$')
cout << st<< "=" << hextoint(st)<<", "<< st <<", "<< intobin(hextoint(st))<<endl;
//else if(st[0]=='%')
//cout << st<< "=" << bintoint(st)<<", "<< inttohex((bintoint(st))<< ", "<<st<< endl;
//else if(st[0]!='$' && st[0]!='%') cout<<st<<"="<<dectoint(st)<<", "<< inttohex(st)<< ", "<<inttobin(st)<<endl;
}
int dectoint(string st)
{
int n=0;
for (int i=0; i<st.length(); i++)
{
char ch = st [i];
n= n*10+(ch-'0');
}
return n;
}
int hextoint (string st)
{
int n=0;
for (int i=1; i<st.length(); i++)
{
char ch= st[i];
n= n*16+(ch-'0');
}
return n;
}
int bintoint (string st)
{
int n=0;
for (int i=1; i<st.length(); i++)
{
char ch= st[i];
n= n*2+(ch-'0');
}
return n;
}
string inttobin (int n)
{
ostringstream buffer;
string result=buffer.str();
int n;
int num;
while (n>0)
{
n=n/2;
num=n%2;
if (n>1)buffer<< num;
else if (n ==1) buffer<<1;
}
return result;
}
//string inttohex (int n);
//string inttodec (int n);
I just want my program to take a number and put it through the hextoint function then pass that to the intobin function! When I compile i get a few errors:inttobin not declared in this scope AND declaration of 'int n' shadows a function
What can I do to fix this in a very simple way?