In: Computer Science
Make the roman project the startup project. Create a function letterToInt with the following interface:
int letterToInt( char letter )
This function should accept a character value as a parameter. This variable represents one symbol in a roman numeral. Your function should return the integer equivalent (e.g., if you pass the function an 'X', it would return the number 10). The function should return -1 if the letter passed to it is not a valid letter in a roman numeral.
Additional Requirements:
Write a main() function to test your function.
The valid roman numerals and their meanings are:
I - 1
V - 5
X - 10
L - 50
C - 100
M - 1000
NOTE: This function does not need to handle a complete roman number such XIV; it only handles one digit Roman Numerals.
#include<iostream>
using namespace std;
int letterToInt( char letter ){
int res=-1;
switch(letter){
case 'I':res=1;break;
case 'V':res=5;break;
case 'X':res=10;break;
case 'L':res=50;break;
case 'C':res=100;break;
case 'M':res=1000;break;
}
return res;
}
int main(){
cout<<letterToInt('M')<<endl;
cout<<letterToInt('C')<<endl;
cout<<letterToInt('X')<<endl;
}
NOTE : PLEASE COMMENT BELOW IF YOU HAVE CONCERNS.
I AM HERE TO HELP YOUIF YOU LIKE MY ANSWER PLEASE RATE AND HELP ME IT IS VERY IMP FOR ME