From 08832c5a8a8d6f749b755e81451741aa81ccbd4c Mon Sep 17 00:00:00 2001 From: fdai7801 Date: Fri, 9 Feb 2024 21:15:02 +0000 Subject: [PATCH] kabrel --- src/main/c/BasicMode.c | 97 ++++++++++++++++++++++++++++-------------- 1 file changed, 64 insertions(+), 33 deletions(-) diff --git a/src/main/c/BasicMode.c b/src/main/c/BasicMode.c index cabb5c4..a9ea1f8 100644 --- a/src/main/c/BasicMode.c +++ b/src/main/c/BasicMode.c @@ -65,40 +65,71 @@ long long int subtraction(long long int a, long long int b) { int main() { - long long int bin1, bin2, dec, result; - char auswahl1, auswahl2; - - do { - printf("what do you want to do?(A for conversion from decimal base to binary base ,B for conversion from binary base to decimal base ,C for Operation in binary base, Q for stop):"); - scanf(" %c", &auswahl1); - switch (auswahl1) { - case 'A': - case 'a': - printf("Enter a decimal number: "); - scanf("%lld", &dec); - bin1 = DecToBin(dec); - printf("%lld in decimal = %lld in binary\n", dec, bin1); - break; - - case 'B': - case 'b': - printf("Enter a binary number: "); - scanf("%lld", &bin1); - dec = BinToDec(bin1); - printf("%lld in binary = %lld in decimalprintf\n"); - break; - - case 'C': - case 'c': - do { - printf("which operation would you like to have?(+ for addition, - for subtraction,* for multiplication and r for return :"); - scanf(" %c", &auswahl2); - - - + long long int bin1, bin2, dec, result; + char auswahl1, auswahl2; + + do { + printf("what do you want to do?(A for conversion from decimal base to binary base ,B for conversion from binary base to decimal base ,C for Operation in binary base, Q for stop):"); + scanf(" %c", &auswahl1); + switch (auswahl1) { + case 'A': + case 'a': + printf("Enter a decimal number: "); + scanf("%lld", &dec); + bin1 = DecToBin(dec); + printf("%lld in decimal = %lld in binary\n", dec, bin1); + break; + case 'B': + case 'b': + printf("Enter a binary number: "); + scanf("%lld", &bin1); + dec = BinToDec(bin1); + printf("%lld in binary = %lld in decimalprintf\n"); + break; - } while (auswahl2 != 'R' && auswahl2 != 'r'); + case 'C': + case 'c': + do { + printf("which operation would you like to have?(+ for addition, - for subtraction,* for multiplication and r for return :"); + scanf(" %c", &auswahl2); + switch (auswahl2) { + case '+': + printf("enter the first binary number: "); + scanf("%lld", &bin1); + printf("enter the second binary number: "); + scanf("%lld", &bin2); + result = addition(bin1, bin2); + + printf("%lld+%d = %lld\n", bin1, bin2, result); + break; + case '-': + printf("enter the first binary number: "); + scanf("%lld", &bin1); + printf("enter the second binary number: "); + scanf("%lld", &bin2); + result = subtraction(bin1, bin2); + + printf("%lld-%lld = %lld\n", bin1, bin2, result); + break; + case '*': + printf("enter the first binary number: "); + scanf("%lld", &bin1); + printf("enter the second binary number: "); + scanf("%lld", &bin2); + result = multiplication(bin1, bin2); + + printf("%lld*%d = %lld\n", bin1, bin2, result); + break; + + case 'R': + case 'r': + printf("return.\n"); + break; + default: + printf("Invalid selection. Please enter again.\n"); + } + } while (auswahl2 != 'R' && auswahl2 != 'r'); break; case 'Q': @@ -108,8 +139,8 @@ int main() { default: printf("Invalid selection. Please enter again.\n"); } + } while (auswahl1 != 'Q' && auswahl1 != 'q'); - } while (auswahl1 != 'Q' && auswahl1 != 'q'); return 0; }