Number base converter in C++

This console program takes a number(which is already a decimal number) and convert it which base you want to convert.

 

#include "stdafx.h"
#include <iostream>
#include <conio.h>
using namespace std;
void converter(int num, int base)//this function is where we do the math
{
if (num == 0)
return;
int x = num % base;
num /= base;
if (x < 0)
num += 1;
converter(num, base);
cout << x ? x + (base * -1) : x;
return;
}
int main()
{
int num, base;
cout << "number to be convert : ";
cin >> num;
cout << "base to be convert : ";
cin >> base;
if (num != 0)
{
converter(num, base);
cout << endl;
}
else
cout << "0" << endl;
getch();
}
Reklamlar
Number base converter in C++

Hi Everyone

I opened this blog for sharing  my experience with programming. I’m  computer science-engineering student in Turkey(it’s my first year). I’ll say this much. I hope this blog will be helpful for someone.

Hi Everyone