Question

*MUST BE IN C PROGRAMMING* Demonstrate the ability to think critically Demonstrate the ability to work...

*MUST BE IN C PROGRAMMING*

  • Demonstrate the ability to think critically
  • Demonstrate the ability to work with strings and chars
  • Demonstrate the ability to design a menu system

Write a simple program that allows the user to enter a number between 1 and 1000.  The program will then display the Roman numeral equivalent.  Allow the user to keep entering numbers for conversion to Roman numerals, or to quit, using a menu system of your own design.

Submission Requirements:

You are to write a good solution - as short, concise, and clever as possible.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <stdio.h>

/* Global data to store roman values */
char roman_data[1000];
int i = 0;

void pre(char n1, char n2)
{
roman_data[i++] = n1;
roman_data[i++] = n2;
}

void post(char data, int num)
{
int j;
for (j = 0; j < num; j++) {
roman_data[i++] = data;
}
}

char *roman(long int data)
{
int j;
long int num;
  
num = data;

if (num <= 0 || num > 1000) {
return NULL;
}
/* repeat the loop until num becoms zero */

while (num != 0) {
if (num >= 1000) {
   /* num greater than 1000 */

post('M', num / 1000);
num = num - (num / 1000) * 1000;
} else if (num >= 500) {
   /* num greater than 500 */

if (num < (500 + 4 * 100)) {
post('D', num / 500);
num = num - (num / 500) * 500;
} else {
pre('C','M');
num = num - (1000-100);
}
} else if (num >= 100) {
/* num greater than 100 */

if (num < (100 + 3 * 100)) {
post('C', num / 100);
num = num - (num / 100) * 100;
} else {
pre('L', 'D');
num = num - (500 - 100);
}
} else if (num >= 50 ) {
   /* num greater than 50 */  

if (num < (50 + 4 * 10)) {
post('L', num / 50);
num = num - (num / 50) * 50;
} else {
pre('X','C');
num = num - (100-10);
}
} else if (num >= 10) {
   /* num greater than 10 */

if (num < (10 + 3 * 10)) {
post('X', num / 10);
num = num - (num / 10) * 10;
} else {
pre('X','L');
num = num - (50 - 10);
}
} else if (num >= 5) {
   /* num greater than 5 */

if (num < (5 + 4 * 1)) {
post('V', num / 5);
num = num - (num / 5) * 5;
} else {
pre('I', 'X');
num = num - (10 - 1);
}
} else if (num >= 1) {
   /* num greater than 1 */

if (num < 4) {
post('I', num / 1);
num = num - (num / 1) * 1;
} else {
pre('I', 'V');
num = num - (5 - 1);
}
}
}

roman_data[i]='\0'; /* Add null character at end of the string */
return(roman_data);
}

int main()
{
   int long val;
   char *ptr;
   char choice;

   while(1){

   printf("Enter the number to convert into Roman: Or -1 to Quit\n");
   scanf("%ld",&val);

if(val == -1){
break;
}
   ptr = roman(val);
   if(ptr == NULL){
       printf("NUmber Not in the range\n");
   }else{
       printf("Roman number is: %s\n",ptr);
   }
roman_data[0]='\0';
i = 0;
   }

return 0;
}

Add a comment
Know the answer?
Add Answer to:
*MUST BE IN C PROGRAMMING* Demonstrate the ability to think critically Demonstrate the ability to work...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Java Programing Code only Ragged Array Assignment Outcome: Student will demonstrate the ability to create and...

    Java Programing Code only Ragged Array Assignment Outcome: Student will demonstrate the ability to create and use a 2D array Student will demonstrate the ability to create and use a jagged array Student will demonstrate the ability to design a menu system Student will demonstrate the ability to think Program Specifications: Write a program that does the following: Uses a menu system Creates an array with less than 25 rows and greater than 5 rows and an unknown number of...

  • c++ object oriented programming

    object oriented programming:Write a program that converts a number entered in decimal toRoman numerals. Your program should consist of a class, say, romanType. Anobject of type romanType should do the following:a. Store the number as a decimal.b. Convert and store the number into roman form.c. Print the number as a Roman numeral or decimal number as requestedby the user.The decimal values of the Roman numerals are:M 1000D 500C 100L 50X 10V 5I 1

  • ***************C PROGRAMMING ONLY************* Demonstrate the ability to create an array on the stack Demonstrate the ability...

    ***************C PROGRAMMING ONLY************* Demonstrate the ability to create an array on the stack Demonstrate the ability to create an array on the heap allowing user to choose the number of values to store. Demonstrate the ability to store an array of Struct values on both the stack and the heap. Program Specifications: 1. Create a struct with at least 3 fields - any struct you want but explain it in your comments in the code. Populate at least 10 elements...

  • Methods and File Output and Exceptions Outcome: Student will demonstrate the ability to write, use and...

    Methods and File Output and Exceptions Outcome: Student will demonstrate the ability to write, use and call methods Student will demonstrate the ability to pass values to and from methods Student will demonstrate the ability to catch exceptions Student will demonstrate the ability to create a text file Student will demonstrate the ability to validate input data Program Specifications: You to write a menu driven program. The program will use a switch statement. The cases will be as follows: Get...

  • Lab 4: Java Fundamentals, Part IV In this assignment, you solve a conversion problem similar to...

    Lab 4: Java Fundamentals, Part IV In this assignment, you solve a conversion problem similar to Programming Challenge 1 of Chapter 3 of your text, page 184 (187 in Edition 5). Given one of the Roman numerals I, II, III, IV, V, VI, VII, VIII, IX, X, XI, XII, XIII, XIV, XV as an input your program must determine and display the corresponding decimal digit 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15....

  • I have to use java programs using netbeans. this course is introduction to java programming so...

    I have to use java programs using netbeans. this course is introduction to java programming so i have to write it in a simple way using till chapter 6 (arrays) you can use (loops , methods , arrays) You will implement a menu-based system for Hangman Game. Hangman is a popular game that allows one player to choose a word and another player to guess it one letter at a time. Implement your system to perform the following tasks: Design...

  • C++ programming For this assignment, write a program that will act as a geometry calculator. The...

    C++ programming For this assignment, write a program that will act as a geometry calculator. The program will be menu-driven and should continue to execute as long as the user wants to continue. Basic Program Logic The program should start by displaying a menu similar to the following: Geometry Calculator 1. Calculate the area of a circle 2. Calculate the area of a triangle 3. Quit Enter your choice(1-3): and get the user's choice as an integer. After the choice...

  • PROGRAMMING LANGUAGE OOP'S WITH C++ Functional Requirements: A jewelry designer friend of mine requires a program...

    PROGRAMMING LANGUAGE OOP'S WITH C++ Functional Requirements: A jewelry designer friend of mine requires a program to hold information about the gemstones he has in his safe. Offer the jewelry designer the following menu that loops until he chooses option 4. 1. Input a gemstone 2. Search for a gemstone by ID number 3. Display all gemstone information with total value 4. Exit ------------------------------------- Gemstone data: ID number (int > 0, must be unique) Gem Name (string, length < 15)...

  • C++ Programming Question: This programming assignment is intended to demonstrate your knowledge of the following: ▪...

    C++ Programming Question: This programming assignment is intended to demonstrate your knowledge of the following: ▪ Writing a while loop ▪ Write functions and calling functions Text Processing [50 points] We would like to demonstrate our ability to control strings and use methods. There are times when a program has to search for and replace certain characters in a string with other characters. This program will look for an individual character, called the key character, inside a target string. It...

  • C++ Programming

    PROGRAM DESCRIPTIONIn this project, you have to write a C++ program to keep track of grades of students using structures and files.You are provided a data file named student.dat. Open the file to view it. Keep a backup of this file all the time since you will be editing this file in the program and may lose the content.The file has multiple rows—each row represents a student. The data items are in order: last name, first name including any middle...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT