Test-Driven Development for Decimal to Different Base Conversion

I want you to use Test-Driven Development and add it to the code below.I have two files one of them the header file.This is the code
#include
#include
#include conversion.h
int main() {
char choice;
printf(REDDecimal BLUE to WHITE Different Base Conversionn);
// Main loop for the program
do {
displayMenu();
printf(WHITEEnter your choice ( RED 1 WHITE / RED 2 WHITE / RED 3 WHITE / RED 4 WHITE ): );
scanf( %c, &choice);
// Switch statement to handle user choice
switch(choice) {
case ‘1’:
convertToBinary(getDecimalInput());
break;
case ‘2’:
convertToOctal(getDecimalInput());
break;
case ‘3’:
convertToHexadecimal(getDecimalInput());
break;
case ‘4’:
printf(Exiting program…n);
exit(0);
default:
printf(Invalid choice. Please choose again.n);
}
printf(BLUEDoWHITE you wantBLUE to WHITE convert another number? (y/n): );
scanf( %c, &choice);
} while(choice == ‘y’ || choice == ‘Y’);
return 0;
}
// Display menu function
void displayMenu() {
printf(n);
printf(RED 1 WHITE. Convert BLUE to Binaryn);
printf(RED 2WHITE . Convert BLUE to WHITE Octaln);
printf(RED 3WHITE. Convert BLUE to WHITE Hexadecimaln);
printf(RED 4 WHITE . BLUE Exitn );
printf(n);
}
// Get decimal input from user
int getDecimalInput() {
int decimal;
printf(Enter a RED decimal WHITE number: );
scanf(%d, &decimal);
// Clear input buffer
while (getchar() != ‘n’);
// Error handling for negative numbers
if (decimal 0) {
binary[i] = decimal % 2;
decimal /= 2;
i++;
}
// Print binary equivalent
for (int j = i – 1; j >= 0; j–) {
printf(RED %d WHITE, binary[j]);
}
}
printf(n);
}
// Convert decimal to octal
void convertToOctal(int decimal) {
printf(Octal equivalent: );
if (decimal == 0)
printf(RED 0 WHITE);
else {
int octal[32];
int i = 0;
// Decimal to octal conversion
while (decimal > 0) {
octal[i] = decimal % 8;
decimal /= 8;
i++;
}
// Print octal equivalent
for (int j = i – 1; j >= 0; j–) {
printf(RED %d WHITE, octal[j]);
}
}
printf(n);
}
// Convert decimal to hexadecimal
void convertToHexadecimal(int decimal) {
printf(Hexadecimal equivalent: );
if (decimal == 0)
printf(RED 0 WHITE);
else {
char hex[32];
int i = 0;
// Decimal to hexadecimal conversion
while (decimal > 0) {
int remainder = decimal % 16;
if (remainder = 0; j–) {
printf(RED %c WHITE, hex[j]);
}
}
printf(n);
}AND THIS IS THE HEADER FILE
#ifndef CONVERSION_H
#define CONVERSION_H
#include
#include
// ANSI color escape codes
#define RED x1b[31m
#define BLUE x1b[34m
#define WHITE x1b[0m
// Function prototypes
void displayMenu();
int getDecimalInput();
void convertToBinary(int decimal);
void convertToOctal(int decimal);
void convertToHexadecimal(int decimal);
#endif /* CONVERSION_H */

The post Test-Driven Development for Decimal to Different Base Conversion appeared first on assignmentscribe.blog.