Do you need this or any other assignment done for you from scratch?
We have qualified writers to help you.
We assure you a quality paper that is 100% free from plagiarism and AI.
You can choose either format of your choice ( Apa, Mla, Havard, Chicago, or any other)
NB: We do not resell your papers. Upon ordering, we do an original paper exclusively for you.
NB: All your data is kept safe from the public.
I want you to use Test-Driven Development and add it to the code below.I have tw
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(RED”Decimal ” BLUE “to” WHITE ” Different Base Conversionn”);
// Main loop for the program
do {
displayMenu();
printf(WHITE”Enter 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(BLUE”Do”WHITE” you want”BLUE ” 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 “2”WHITE “. Convert ” BLUE “to ” WHITE “Octaln”);
printf(RED “3”WHITE”. 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) {
printf("Error: Negative numbers are not allowed.n");
exit(1);
}
return decimal;
}
// Convert decimal to binary
void convertToBinary(int decimal) {
printf(BLUE"Binary" WHITE" equivalent: ");
if (decimal == 0)
printf(RED "0" WHITE);
else {
int binary[32];
int i = 0;
// Decimal to binary conversion
while (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 < 10)
hex[i] = remainder + '0';
else
hex[i] = remainder + 55; // Convert to ASCII values of A-F
decimal /= 16;
i++;
}
// Print hexadecimal equivalent
for (int j = i - 1; j >= 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 */
Do you need this or any other assignment done for you from scratch?
We have qualified writers to help you.
We assure you a quality paper that is 100% free from plagiarism and AI.
You can choose either format of your choice ( Apa, Mla, Havard, Chicago, or any other)
NB: We do not resell your papers. Upon ordering, we do an original paper exclusively for you.
NB: All your data is kept safe from the public.
Place this order or similar order and get an amazing discount. USE Discount code “GET20” for 20% discount