1

i am done with my c++ class and got a passing grade but this project problem that i was suppose to do is incomplete and is stuck in my head so I want to try and finish it but i am stuck here... not sure if i am using a string correctly or how to even use one. I was told that I would need one to do a radix other than 10.

q1: I keep getting and overloaded function and I tried to solve this but i am unsure of what else to do can i get a hint?

q2: I am also having having trouble convert a int to a string and i looked it up but i am not sure how to use itoa or sprintf ...

```
#include<iostream>
#include<string>
#include<cmath>
using namespace std;
int conversion ();
int conversion (int ,int , int);
int i=0,j=0,p[50];
int main(){
int radixa,radixb,number;
cout<<"radix a(2-16) : ";
// radixa=10;
cin>>radixa;
cout<<endl;
cout<<"radix b(2-16): ";
cin>>radixb;
cout<<endl;
cout<<"number to be converted: ";
cin>>number;
cout<<endl;
conversion (radixa,radixb,number);
conversion();
cout<<endl;
}
int conversion(){
i--;
for (;i>=0;i--){
if ((p[i] >= 0)){
switch (p[i]){
case 0:cout<<0; break;
case 1:cout<<1; break;
case 2:cout<<2; break;
case 3:cout<<3; break;
case 4:cout<<4; break;
case 5:cout<<5; break;
case 6:cout<<6; break;
case 7:cout<<7; break;
case 8:cout<<8; break;
case 9:cout<<9; break;
case 10:cout<<'a'; break;
case 11:cout<<'b'; break;
case 12:cout<<'c'; break;
case 13:cout<<'d'; break;
case 14:cout<<'e'; break;
case 15:cout<<'f'; break;
}
}
}
return 0;
}
int conversion (int radixa, int radixb, int number){
int remainder=0;
if (radixa == 10){
while( number >0 ){
remainder = number % radixb;
number /= radixb;
p[i] = remainder;
i++;
j++;}
}
//this is where i try to convert radixa as something
//other than 10 in to an array
// where I can then convert it into a
// different base if I exclude this portion below
//I can use base 10 as my radix a i can convert
// to base 2-16
// i am trying to convert everything in to base 10
// first then convert it out as whatever radixb
// has been required to output
if (radixa !=10 || radixa !=16){
while (number>0){
string num = number;
string nnum; // not sure this works but i thought i might need a second string
nnum= number/(pow(radixa,num.length()-1));
number%=(pow(radixa,num.length()-1));
i++;
}
}
return 0;
}
```

*Edited 3 Years Ago by mike_2000_17*: Fixed formatting