Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Name: James Inglis
- * Course: Data Structures and Algorithms
- * Professor: John Drugan
- * Date: 9/12/14
- * Description:
- */
- #include <iostream>
- #include <cstring>
- #include <string>
- using namespace std;
- int main()
- {
- float decimalForm = 0.0, total;
- int i;
- string romansNum;
- // Getting the Roman Numeral number.
- cout << "Please enter in Roman numeral characters. For example (MCXIV) : ";
- getline(cin, romansNum);
- //char store;
- total = 0.0;
- for(i = 0; i < romansNum.length(); i++)
- {
- romansNum[i];
- }
- for(i = 0; i < romansNum.length(); i++)
- {
- switch(romansNum[i])
- {
- case 'M':
- decimalForm = 1000;
- total += decimalForm;
- break;
- case 'D':
- decimalForm = 500;
- total += decimalForm;
- break;
- case 'C':
- decimalForm = 100;
- total += decimalForm;
- break;
- case 'L':
- decimalForm = 50;
- total += decimalForm;
- break;
- case 'X':
- decimalForm = 10;
- total += decimalForm;
- break;
- case 'V':
- decimalForm = 5;
- total += decimalForm;
- break;
- case 'I':
- decimalForm = 1;
- total += decimalForm;
- break;
- default:
- cerr << "Im sorry. I dont reconize that letter" << endl;
- }
- }
- cout << "The number in decimal form: " << total << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement