Skip to content

Commit 988da0c

Browse files
committed
Fix: Now work with negative numbers
1 parent 8bbeaec commit 988da0c

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

exercises/binary_converter.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
using namespace std;
1111

12-
void BinR(unsigned long int num){
12+
void BinR(long int num){
1313
if(!num){
1414
return;
1515
}
@@ -26,7 +26,7 @@ void BinR(unsigned long int num){
2626
}
2727

2828
int main(){
29-
unsigned long int num;
29+
long int num;
3030

3131
cout << "Insert first number: ";
3232
cin >> num;
@@ -36,6 +36,11 @@ int main(){
3636
exit(1);
3737
}
3838

39+
if(num < 0){
40+
num *= -1;
41+
cout<< "Warning: The given value is a negative number. Switching to "<< num << endl;
42+
}
43+
3944
cout<< "The binary number is: ";
4045
BinR(num);
4146

0 commit comments

Comments
 (0)