Advertisement
jinglis

Roman to Decimal(In Progress)

Sep 12th, 2014
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.31 KB | None | 0 0
  1. /* Name: James Inglis
  2.  * Course: Data Structures and Algorithms
  3.  * Professor: John Drugan
  4.  * Date: 9/12/14
  5.  * Description:
  6.  */
  7.  
  8. #include <iostream>
  9. #include <cstring>
  10. #include <string>
  11. using namespace std;
  12.  
  13. int main()
  14. {
  15.     float decimalForm = 0.0, total;
  16.     int i;
  17.     string romansNum;
  18.  
  19.  
  20.     // Getting the Roman Numeral number.
  21.     cout << "Please enter in Roman numeral characters. For example (MCXIV) : ";
  22.     getline(cin, romansNum);
  23.     //char store;
  24.  
  25.     total = 0.0;
  26.  
  27.     for(i = 0; i < romansNum.length(); i++)
  28.     {
  29.          romansNum[i];
  30.     }
  31.  
  32.  
  33.     for(i = 0; i < romansNum.length(); i++)
  34.     {
  35.          switch(romansNum[i])
  36.          {
  37.          case 'M':
  38.              decimalForm = 1000;
  39.              total += decimalForm;
  40.              break;
  41.  
  42.          case 'D':
  43.              decimalForm = 500;
  44.              total += decimalForm;
  45.              break;
  46.  
  47.          case 'C':
  48.              decimalForm = 100;
  49.              total += decimalForm;
  50.              break;
  51.  
  52.          case 'L':
  53.              decimalForm = 50;
  54.              total += decimalForm;
  55.             break;
  56.  
  57.          case 'X':
  58.              decimalForm = 10;
  59.              total += decimalForm;
  60.              break;
  61.  
  62.          case 'V':
  63.              decimalForm = 5;
  64.              total += decimalForm;
  65.              break;
  66.  
  67.          case 'I':
  68.              decimalForm = 1;
  69.              total += decimalForm;
  70.              break;
  71.  
  72.          default:
  73.              cerr << "Im sorry. I dont reconize that letter" << endl;
  74.          }
  75.     }
  76.  
  77.     cout << "The number in decimal form: " << total << endl;
  78.  
  79.     return 0;
  80.  
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement