0
#include <iostream>
using namespace std;

//function protoytypes
int roman2integer();
bool isValidRoman(string & r);
int findIt(char ch);

int main()
{
    int choice;
    
    do{
     switch(choice)
     {
           case 1: roman2integer();
                   break;
           case 2: //integer2roman();
                   break;
           case 3: //quit=true;
                   break;
           default:
                   return 0;
    };
    
    
    }while(       );
    
    return 0;
}
///////////////////////////////////////////////////////////////////////////////
int roman2integer()
{
     string roman; 
     int integerValue=0;
     bool valid;
     //SIZE=roman.lengeth();
     
     do{
        cout << "Enter in a number in roman numerals: ";
        cin >> roman;
        valid = isValidRoman(roman);
     }while(      );
     
     for(int x=0; x<SIZE; x++)
     {
        if(findIt(roman[x]) < (findIt(roman[x+]))
           integerValue-=findIt(roman[x]);
        else
           integerValue+=findIt(roman[x]);
     }
     
     return integerValue;
}
///////////////////////////////////////////////////////////////////////////////
bool isValidRoman(string & r)
{
    
     for(int x=0; x < r.length(); x++)
     {
         r[x] = toupper(r[x]);   
             
         switch(r[x])
         {
               case 1: 'I';
                       break;
               case 2: 'V';
                       break;
               case 3: 'X';
                       break;
               case 4: 'L';
                       break;
               case 5: 'C';
                       break;
               case 6: 'D';
                       break;
               case 7: 'M';
                       break;
               default:
                       return false;
        };
     }
     
    
         
}
///////////////////////////////////////////////////////////////////////////////     
int findIt(char ch)
{
    if(ch=='I')
       return 1;
    if(ch=='V')
       return 5;
    if(ch=='X')
       return 10;
    if(ch=='L')
       return 50;
    if(ch=='C')
       return 100;
    if(ch=='D')
       return 500;
    if(ch=='M')
       return 1000;
}

I know my codes has errors which i will fix but if u wanna help me fix them that would be great but in my validating function im having a hard time figuring out what code to write so that the roman numeral rules are validated so i need help with that if anyone is willing to.

Edited by WaltP: Added CODE tags -- with all the help about them, how could you miss using them????

3
Contributors
4
Replies
5
Views
7 Years
Discussion Span
Last Post by Salem
Featured Replies
  • 1

    line 43: you need some way to stop the loop. using a line like: while(!valid); should do it. line 84 should be: return true; else how are you going to indicate that all char in the input are valid char for a roman numeral? Read More

0

thanks for fixing my for me so it look right on here

Edited by moods125: n/a

1

line 43: you need some way to stop the loop. using a line like:
while(!valid);
should do it.

line 84 should be:
return true;
else how are you going to indicate that all char in the input are valid char for a roman numeral?

0

thanks man that helps a little but not what i was looking for but still it helps

0

> I know my codes has errors which i will fix but if u wanna help me fix them that would be great but in my validating function
So how are we supposed to tell the difference between the errors you can fix, and the errors you can't?.

That would be damn convenient for you, to have a polished program right off the bat.

To me, it looks like a "fill in the missing blanks" homework question. You couldn't possibly have written it like that, and be confused about what to do next. Not least fixing all the compiler error messages for example.

Better questions would be:
- Here is my program, it doesn't compile, and I don't know what "...." error message means.
- Here is my program, it compiles, but it produces the wrong answer when I type in "....", but it works if I type in "....".

What you posted was "Here is my program, fix it".

This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.