Need help with a CS 1 assignment please!

Im trying to create a program that converts roman numerals to its arabic equivalent. This is what I have so far but im blanking out, can someone help me finish this. The roman numerals are comming from a batch file. Im not allowed to used strings, arrays, vectors. I can use Char. and I am accounting for exceptions (such as IV) I dont know if its because im burnt out but I just cant seem to finish. Thank you much in advance, anything is greatly appreciated




int main()
{

char currentChar = 0;
int currentValue = 0;
int lastValue = 0;
int sum = 0;
while(true)
{
if(currentChar = '\n') // adds final value and exits loop
{
sum += lastValue;
break;
}


currentValue = romToInt(currentChar);

if(currentValue > lastValue) // if 'I' preceded 'V', etc.
sum -= lastValue;
else
sum += lastValue;

lastValue = currentValue; // set up for next iteration

// TODO: set currentChar to the next character in the line

} // end while


} // end main





int romToInt(char c)
{
int value = 0;

switch(c)
{
case 'I': value = 1;
break;
case 'V': value = 5;
break;
case 'X': value = 10;
break;
case 'L': value = 50;
break;
case 'C': value = 100;
break
case 'D': value = 500;
break
case 'M': value = 1000;
break

} // end switch
return value;

} // ends funtion
Last edited on
Topic archived. No new replies allowed.