Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In C language Write an interactive program that can be used as a Roman numeral c

ID: 3774594 • Letter: I

Question

In C language
Write an interactive program that can be used as a Roman numeral calculator. The program will accept two Roman numerals and an arithmetic operation from the keyboard and will print out the result of the operation. The values of the Roman numeral digits are as follows:

I 1

V 5

X 10

L 50

C 100

D 500

M 1000

Each Roman numeral must start with a digit of highest value and must end with a digit of lowest value. That is, 9 will be represented as VIIII instead of IX. The recognizable arithmetic operations are integer addition, integer subtraction, integer multiplication, and modulus. Internally, the program will convert the Roman numerals into integers, perform the required operation, and then convert the result back to Roman numerals for printing. Input and output characters one at a time. Do not use strings, arrays, functions, or anything else we have not covered in class. Negative numbers are not acceptable as input. The only instance of negative numbers is when the first number is smaller than the second and the operation is subtraction, in which case a negative Roman numeral will result and be printed. If division by zero is attempted by the user, alert the user, and accept a different arithmetic operation. Much of the code is given below in a version that does not use functions, and again below that is a version that does use functions. This use of functions to make main look simpler is sometimes called parameterized. Your final program should be parameterized.

Write an interactive program that can be used as a Roman The will accept two Roman numerals and an arithmetic from the keyboard and will print out the result operation. The values of the Roman numeral digits are as follows: 100 1000 Each Roman numeral must start with a digit of highest value and must end with a digit of lowest value. That is, 9 will be represented as VIIII instead of IX. The recognizable arithmetic operations are integer addition, integer subtraction, integer multiplication, and modulus. Internally, the program will convert the Roman numerals into integers, perform the required operation, anc then convert the result back to Roman numerals for printing. Input and output characters one at a time. Do not use strings, arrays. functions, or anything else we have not covered in class. Negative numbers are not acceptable as input. The only instance of negative numbers is when the first number is smaller than the second and the operation is subtraction, in which case a negative numeral will result and be printed. If division by zero is attempted by the user, alert the user, and accept a different arithmetic operation. Much of the code is given below in a version that does not use functions, and again below that is a version that does use functions. This use of functions to make main look simpler is sometimes called Your final program should be parameteized. parameterized. Sample Hail Caesar! Welcome to Roman Calculator Enter first number: MMxI The first number is 2011 Enter second number VIII The second number is 8 operation Answer: 2019 In Roman: MMXVIIII Press e to quit, any other key to continue Enter first number: XXII The first number is 22 Enter second number: VII The second number is 7 Enter operation t In Roman III Press e to quit, any other key to continue. Thanks for playing! key continue

Explanation / Answer

Answer:

#include <stdio.h>

//main program

int main ()

{

        //declares variable

        int numb;

        printf("Enter your input:");

        scanf("%d", &numb);

        //Prints the roman number

        printf("Roman Number: ");

        while (numb > 0) {

                if (numb >= 1000) {

                     

                        printf("M");

                        numb = numb - 1000;

                } else if (numb >= 500) {

                       

                        if (numb >= 900) {

                                printf("CM");

                                numb = numb - 900;

                        } else {

                                printf("D");

                                numb = numb - 500;

                        }

                } else if (numb >= 100) {

                       

                        if (numb >= 400) {

                                printf("CD");

                                numb = numb - 400;

                        } else {

                                printf("C");

                                numb = numb - 100;

                        }

                } else if (numb >= 50) {

                      

                        if (numb >= 90) {

                                printf("XC");

                                numb = numb - 90;

                        } else {

                                printf("L");

                                numb = numb - 50;

                        }

                } else if (numb >= 9) {

                       

                        if (numb >= 40) {

                                printf("XL");

                                numb = numb - 40;

                        } else if (numb == 9) {

                                printf("IX");

                                numb = numb - 9;

                        } else {

                                printf("X");

                                numb = numb - 10;

                        }

                } else if (numb >= 4) {

                      

                        if (numb >= 5) {

                                printf("V");

                                numb = numb - 5;

                        } else {

                                printf("IV");

                                numb = numb - 4;

                        }

                } else {

                        printf("I");

                        numb = numb - 1;

                }

        }

        printf(" ");

}