Thanks for any help in advance.
I was given an assignment that takes in the following inputs:
init_base which is the base we are converting to. 2<=init_base and 36>= init_base
in_num which is the decimal number that is to be converted
in_num gets written to multiple times for each decimal number
the input is terminated with a -1
I was told to use the capital letters of the alphabet for when the number is larger than 9.
I have written code for the solution. The code runs but I constantly get a weird output. I am not to sure why this is. I think it has something to do with my data type conversions. However I am not too sure what is going wrong.
#include <iostream>
#include <cmath>
#include <string>
#include <stdlib.h>
#include <algorithm> 
using namespace std;
string ans;
int counter = 0;
bool Alpha_check(int val){
    if(val>9){
        return true;
    }
    else{
        return false;
    }
}
char Al_conv(int val){
    if(Alpha_check(val)){
        return char(val+55);
    }
    else {
         return char((val-48)+'0'); 
    }
}
void add_On(int c){
    ans.append(Al_conv(c));
    counter++;
}
int div_loop(int num, int base){    
    int temp = int(num/base);
    int temp2 = int(num%base);
    add_On(temp2);
    return temp;
}
void add_line(int number){
    ans[number] = '\n';
}
int main(){
    int init_base, in_num = 0;
    cin >> init_base;
    cin >> in_num;
    do{
        string rem;
        int init_count = counter;
        while(in_num!=0){
            in_num = div_loop(in_num,init_base);
        }
        int helper = int(floor((counter-init_count)/2));
        for(int y = 0; y < helper; y++){
            int temp = ans[y+init_count];
            ans[y+init_count] = ans[(counter-1)-y];
            ans[(counter-1)-y] = temp;
        }
        add_line(counter);
        counter++; 
        cin >> in_num;
    }while(in_num!=-1);
    ans[counter] = '\0';
    for(int gh = 0; gh < ans.length(); gh++){
        cout << ans[gh];
    }
    cout << endl;
     return 0;
}
Here is also a link for you to follow http://ideone.com/qFOtyl to check out the output.
 
    