Exercise 3 – Roman Numerals Exercise Tasks: Create a visual studio C++ project exercise3 and submit the cpp file when completed Create a C++ program that converts integers between 1 and 3999 into the corresponding roman numerals. Your solution should print an error message for incorrect input. The following roman numeral conversions should prove useful: 1. I        6. VI           50. L         900. CM 2. II        9. IX          90. XC    1000. M 4. IV       10. X        100. C    5. V        40. XL      500 D. Modify the following tester code to obtain an integer from the user and check that it is between 1 and 3999. Then print out the corresponding roman numerals. While the sample code uses an ifthenelse, you could also use a switch statement.   /****************************************************** * Roman Numeral Converter  August 13 * converts base 10 positive integer >=0 <4000 to roman numerals * @author  */     #include   using namespace std; int main(){     int thousands, hundreds, tens, ones;     int inputNum, residualNum;       cout << "Please enter a positive integer <= 3999: ";     cin >> inputNum;       if(inputNum < 0 || inputNum >= 4000) {         cout << "that input was not correct";     } else {                  // thousands digit         residualNum = inputNum;                  thousands = residualNum / 1000;         residualNum = residualNum % 1000;           if(thousands == 3) {             cout << "MMM";         } else if (thousands == 2) {             cout << "MM";         } else if (thousands == 1) {             cout << "M";         }           //hundreds digit         hundreds = residualNum / 100;         residualNum = residualNum % 100;           // you need to fill in the missing code here

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Exercise 3 – Roman Numerals

Exercise Tasks: Create a visual studio C++ project exercise3 and submit the cpp file when completed

Create a C++ program that converts integers between 1 and 3999 into the corresponding roman numerals. Your solution should print an error message for incorrect input. The following roman numeral conversions should prove useful:

1. I        6. VI           50. L         900. CM
2. II        9. IX          90. XC    1000. M
4. IV       10. X        100. C   
5. V        40. XL      500 D.

Modify the following tester code to obtain an integer from the user and check that it is between 1 and 3999. Then print out the corresponding roman numerals. While the sample code uses an ifthenelse, you could also use a switch statement.

 

/******************************************************

* Roman Numeral Converter  August 13

* converts base 10 positive integer >=0 <4000 to roman numerals

* @author <your name here>

*/

 

 

#include <iostream>

 

using namespace std;

int main(){

    int thousands, hundreds, tens, ones;

    int inputNum, residualNum;

 

    cout << "Please enter a positive integer <= 3999: ";

    cin >> inputNum;

 

    if(inputNum < 0 || inputNum >= 4000) {

        cout << "that input was not correct";

    } else {

        

        // thousands digit

        residualNum = inputNum;

        

        thousands = residualNum / 1000;

        residualNum = residualNum % 1000;

 

        if(thousands == 3) {

            cout << "MMM";

        } else if (thousands == 2) {

            cout << "MM";

        } else if (thousands == 1) {

            cout << "M";

        }

 

        //hundreds digit

        hundreds = residualNum / 100;

        residualNum = residualNum % 100;

 

        // you need to fill in the missing code here

    }

}

Expert Solution
steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Introduction to Coding
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education