-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBaseSystem.cpp
45 lines (38 loc) · 899 Bytes
/
BaseSystem.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/*
Randall Hall
C++ program to convert an integer in base 10 to a defined base
*/
#include <iostream>
using namespace std;
void decToBin (int, int);
int main()
{
int decimal;
int base;
cout << "Enter a non-negative base ten integer to convert to a different base: ";
cin >> decimal;
cout << "Convert to what base? ";
cin >> base;
do
{
if (decimal >= 0)
{
cout << "" << decimal << " (base 10) = ";
decToBin (decimal, base);
cout << " (base " << base << "). " << endl;
}
else
cout << "" << decimal << " is not a non-negative integer. " << endl;
} while (cin >> decimal);
return 0;
}
void decToBin(int num, int base)
{
if (num > 0)
{
decToBin (num/base, base);
cout << num % base;
}
else
cout << "0";
}