Question: Why does my code not match the output? #include #include #include using namespace std; / / Converts a single digit to its Roman numeral representation

Why does my code not match the output?
#include
#include
#include
using namespace std;
// Converts a single digit to its Roman numeral representation
string roman_digit(int digit, string one, string five, string ten){
if (digit ==1) return one;
if (digit ==2) return one + one;
if (digit ==3) return one + one + one;
if (digit ==4) return one + five;
if (digit ==5) return five;
if (digit ==6) return five + one;
if (digit ==7) return five + one + one;
if (digit ==8) return five + one + one + one;
if (digit ==9) return one + ten;
return "";
}
// Converts an integer to its Roman numeral representation
string roman_numeral(int n){
string result ="";
// Process the thousands place
result += roman_digit(n /1000,"M","","");
n %=1000;
// Process the hundreds place
result += roman_digit(n /100,"C","D","M");
n %=100;
// Process the tens place
result += roman_digit(n /10,"X","L","C");
n %=10;
// Process the ones place
result += roman_digit(n, "I", "V","X");
return result;
}
int main(){
// Constants defining the range and start year of the Super Bowl
const int START_SUPERBOWL =1967;
const int MIN_ROMAN =1;
const int MAX_ROMAN =3999;
const int MAX_YEAR = START_SUPERBOWL + MAX_ROMAN -1;
// Display the welcome message
cout "***********************************************************" endl;
cout "* The Super Bowl is the annual final playoff game *" endl;
cout "* of the NFL to determine the league champion. *" endl;
cout "* The first Super Bowl took place on January 15,1967.*" endl;
cout "* Super Bowl I (Los Angeles Memorial Coliseum)--->1967*" endl;
cout "* This Roman Numerals Convertor is written by Yi Pike. *" endl;
cout "* If you had a time machine, which year of Super Bowl *" endl;
cout "* would you want to attend (1967-5965)?*" endl;
cout "***********************************************************" endl;
string input;
while (true){
cout "Please enter the year you want to attend (click Q or q to quit): ";
cin >> input;
// Check if user wants to quit
if (input =="Q"|| input =="q"){
cout "Back to 2023, and have a great day!" endl;
break;
}
int year;
try {
// Convert input to integer
year = stoi(input);
}
catch (...){
// Handle non-numeric input
cout "Please use a four-digit number to represent a year (1967-5965)!" endl;
cin.clear(); // Clear the error flag on cin
cin.ignore(numeric_limits::max(),'
'); // Ignore the rest of the invalid input
continue;
}
// Check if the year is within the valid range
if (year START_SUPERBOWL){
cout "The time machine will bring you to the year of " year ": Wait!!! The year you entered is TOO EARLY for the first Super Bowl!" endl;
}
else if (year > MAX_YEAR){
cout "The time machine will bring you to the year of " year ": Hold on!!! The year you entered is TOO BIG for Roman numerals!" endl;
}
else {
// Calculate the Super Bowl number and display the result
int super_bowl_number = year - START_SUPERBOWL +1;
cout "The time machine will bring you to the year of " year ": It is Super Bowl " roman_numeral(super_bowl_number) endl;
}
cout "We will help you find out the result and other interesting information...next time:)" endl;
}
return 0;
}
 Why does my code not match the output? #include #include #include

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!