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

In C language: 2) Roman Calculator Write an interactive program that can be used

ID: 3775484 • Letter: I

Question

In C language: 2) Roman Calculator Write an interactive program that can be used as The will accept two numerals an from the keyboard and will print out the result of the operation. The values of the Roman numeral digits are as follows: 10 100 500 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. 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. Sample output Hail Caesar! Welcome to Roman Calculator Enter first number: MMDKI The first number is 2011 Enter second number VIII The second number is 8 Enter operation Answer: 2019 In Roman MMXVIIII Press 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 Answer: In Roman III Press e quit, any other key to continue. Thanks for playing to unit key to continue

Explanation / Answer

#include <stdio.h>

#include <conio.h>

#include <stdlib.h>

#include <time.h>

#pragma warning (disable:4996)

char num1, num2;

int opchar;

int yesno;

int ch1, ch2;

int ans;

int opOK;

int again;

time_t t;

void main()

{

                printf("Welcome to the Roman Calculator. ");

               

                do{

                                ch1 = ch2 = num1 = num2 = ans = 0;

                                again = 2;

                                printf("Please enter your first number: ");

                                do{

                               

                                num1 = getche();

                                switch(num1)

                                {

                                case 'M':

                                case 'm':

                                                ch1 += 1000;

                                                break;

                                case 'D':

                                case 'd':

                                                ch1 += 500;

                                                break;

                                case 'C':

                                case 'c':

                                                ch1 += 100;

                                                break;

                                case 'L':

                                case 'l':

                                                ch1 += 50;

                                                break;

                                case 'X':

                                case 'x':

                                                ch1 += 10;

                                                break;

                                case 'V':

                                case 'v':

                                                ch1 += 5;

                                                break;

                                case 'I':

                                case 'i':

                                                ch1 =+ 1;

                                                break;

                                default:

                               

                                                break;

                                }

                }while(num1 != 'Q' && num1 !='q'); //ends loop for 1st #

                printf(" First number = %d ", ch1);

                printf("Please enter your second number: ");

                do{

                                //gets user input

                                num2 = getche();

                                switch(num2)

                                {

                                case 'M':

                                case 'm':

                                                ch1 += 1000;

                                                break;

                                case 'D':

                                case 'd':

                                                ch1 += 500;

                                                break;

                                case 'C':

                                case 'c':

                                                ch1 += 100;

                                                break;

                                case 'L':

                                case 'l':

                                                ch1 += 50;

                                                break;

                                case 'X':

                                case 'x':

                                                ch1 += 10;

                                                break;

                                case 'V':

                                case 'v':

                                                ch1 += 5;

                                                break;

                                case 'I':

                                case 'i':

                                                ch1 =+ 1;

                                                break;

                                default:

                                                                                                break;

                                }

                }while(num2 != 'Q' && num2 !='q'); //ends loop for 2nd #

                printf(" Second number = %d ", ch2);

                do{

                                printf(" Please select and operation (*, /, +, -, %): ");

                                opchar = getche(); //get user's input

                               

                                switch(opchar)

                                {

                                case '+':

                                                ans = ch1 + ch2;

                                                opOK = true;

                                                break;

                                case '-':

                                                ans = ch1 - ch2;

                                                opOK = true;

                                                break;

                                case '*':

                                                ans = ch1 * ch2;

                                                opOK = true;

                                                break;

                                case '/':

                                                if(num2 ==0) //catches undefined answers

                                                {

                                                                printf(" Cannot divide by zero. Select another operation. ");

                                                                opOK = false;

                                                                break;

                                                }

                                                else

                                                {

                                                                ans = ch1 / ch2;

                                                                opOK = true;

                                                                break;

                                                }

defalut:

                                                printf("Unidentified operation. Select another operation. ");

                                                opOK = false;

                                }

                }while(opOK != true); //exits the loop when opOK becomes true

               

                printf(" The answer is %d Roman Numeral answer is ", ans);

                if(ans < 0)

                {

                                printf("-");

                                ans *= -1;

                }

                while(ans >= 1000)

                {

                                printf("M");

                                ans -= 1000;

                }

                while(ans >= 500)

                {

                                printf("D");

                                ans -= 500;

                }

                while(ans >= 100)

                {

                                printf("C");

                                ans -= 100;

                }

                while(ans >= 50)

                {

                                printf("L");

                                                ans -= 50;

                }

                while(ans >= 10)

                {

                                printf("X");

                                ans -= 10;

                }

                while(ans>= 5)

                {

                                printf("V");

                                ans -= 5;

                }

                while(ans >= 1)

                {

                                printf("I");

                                ans -= 1;

                }

                printf(" Do you want to play again? (y)es or (n)o?");

                do{

                                yesno=getche();

                                switch(yesno)

                                {

                                case 'Y':

                                case 'y':

                                                again = 1;

                                                break;

                                case 'N':

                                case 'n':

                                                again = 0;

                                                break;

                                default:

                                                printf(" Not a valid entry, please select (y)es or (n)o. ");

                                }

                }while(again ==2); //exits loop when the user enters y or n

                printf(" "); //line break

                }while(again==1); //ends main loop

                printf(" Bye-bye! ");

                }