Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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 romandigitint digit, string one, string five, string ten
if digit return one;
if digit return one one;
if digit return one one one;
if digit return one five;
if digit return five;
if digit return five one;
if digit return five one one;
if digit return five one one one;
if digit return one ten;
return ;
Converts an integer to its Roman numeral representation
string romannumeralint n
string result ;
Process the thousands place
result romandigitn M;
n ;
Process the hundreds place
result romandigitn CDM;
n ;
Process the tens place
result romandigitn XLC;
n ;
Process the ones place
result romandigitn "I", VX;
return result;
int main
Constants defining the range and start year of the Super Bowl
const int STARTSUPERBOWL ;
const int MINROMAN ;
const int MAXROMAN ;
const int MAXYEAR STARTSUPERBOWL MAXROMAN ;
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 endl;
cout Super Bowl I Los Angeles Memorial Coliseum 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 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 and have a great day!" endl;
break;
int year;
try
Convert input to integer
year stoiinput;
catch
Handle nonnumeric input
cout "Please use a fourdigit number to represent a year endl;
cin.clear; Clear the error flag on cin
cin.ignorenumericlimits::max
; Ignore the rest of the invalid input
continue;
Check if the year is within the valid range
if year STARTSUPERBOWL
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 MAXYEAR
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 superbowlnumber year STARTSUPERBOWL ;
cout "The time machine will bring you to the year of year : It is Super Bowl romannumeralsuperbowlnumber endl;
cout We will help you find out the result and other interesting information...next time: endl;
return ;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started