Programming Challenge Chapter 4 – Q #2 Roman Numeral Converter – Tony Gaddis – Starting Out With C++
Problem: -
Solution: -
#include<iostream>
using namespace std;
int main()
{
//Declare a Variable
int num;
//Take Input From The User
cout << "Enter a number which
you want to convert in Roman: ";
cin >> num;
//Use Switch Statement For 1
to 10 Cases
switch (num)
{
case 1:
cout << "Roman of 1 is:
i";
break;
case 2:
cout << "Roman of 2 is:
ii";
break;
case 3:
cout << "Roman of 3 is:
iii";
break;
case 4:
cout << "Roman of 4 is:
iv";
break;
case 5:
cout << "Roman of 5 is:
v";
break;
case 6:
cout << "Roman of 6 is:
vi";
break;
case 7:
cout << "Roman of 7 is:
vii";
break;
case 8:
cout << "Roman of 8 is:
viii";
break;
case 9:
cout << "Roman of 9 is:
ix";
break;
case 10:
cout << "Roman of 10 is:
x";
break;
default: //Use Default For Input Validation
cout << "Enter number between
1 to 10";
}
//Return 0 To The Main
Function
return 0;
}
This is the solution of this question
OUTPUT OF THIS QUESTION
Explanation of this Solution
Solution Explain With Comments in Solution.
Also, I attach CPP file of this problem. You can download this file
0 Comments