From 6bac07c7970adf4a6b94c6f831d8cba949b649fc Mon Sep 17 00:00:00 2001 From: Viktor Varoutis <92715836+Jimvar@users.noreply.github.com> Date: Tue, 26 Nov 2024 08:45:42 +0200 Subject: [PATCH] Added negative reading number functionality to read_number(), so that it knows when they input a negative bet --- blackjackfolder/cardsystem.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/blackjackfolder/cardsystem.c b/blackjackfolder/cardsystem.c index f195872..458101c 100644 --- a/blackjackfolder/cardsystem.c +++ b/blackjackfolder/cardsystem.c @@ -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(); } @@ -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; } @@ -231,4 +235,4 @@ int game(char name[], int deck[][4][14], int *played_cards, int double_down, int } } -} \ No newline at end of file +}