Skip to content

Commit

Permalink
Added negative reading number functionality to read_number(), so that…
Browse files Browse the repository at this point in the history
… it knows when they input a negative bet
  • Loading branch information
Jimvar authored Nov 26, 2024
1 parent 04cd20a commit 6bac07c
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion blackjackfolder/cardsystem.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@

long long read_number() {
long long number = 0;
int negative_flag = 0;

char c = getchar();

while (!(c >= '0' && c <= '9')) {
if(c=='-') negative_flag = 1;
c = getchar();
}

Expand All @@ -22,6 +24,8 @@ long long read_number() {
else if(c=='m' || c=='M') number *= 1000000;
else if(c=='b' || c=='B') number *= 1000000000;

if(negative_flag) number *= -1;

return number;
}

Expand Down Expand Up @@ -231,4 +235,4 @@ int game(char name[], int deck[][4][14], int *played_cards, int double_down, int
}
}

}
}

0 comments on commit 6bac07c

Please sign in to comment.