Thread: Need help
View Single Post
 
Reply
Posted 2003-11-18, 10:50 PM in reply to Hades-Knight's post "Need help"
#include <stdio.h>

int main(void)
{
int x, now, total, i;
now = 0;
char romanNumeral[50];

printf("enter roman numeral\n");
gets(romanNumeral);

for (i = strlen(romanNumeral) - 1); i >= 0; i--)
{
if (romanNumeral[i] == 'M') {

x = 1000;

}
else if (romanNumeral[i] == 'D') {

x = 500;

}
else if (romanNumeral[i]== 'C') {

x = 100;

}
else if (romanNumeral[i] == 'L') {

x = 50;

}
else if (romanNumeral[i] == 'X') {

x = 10;

}
else if (romanNumeral[i] == 'V') {

x = 5;

}
else if (romanNumeral[i] == 'I') {

x = 1;

}

if (x >= now) {

total += x;

} else {

total -= x;

}

now = x;

}

printf("%d \n", total);

}





sorry if it's messy but i think you get the gist of it


ill see if i can do ur other 1 tomorrow

i haven't compiled 2 check for syntax errors but i think the logic should work..

and i hope u needed C...lol

Last edited by Demosthenes; 2003-11-18 at 11:09 PM.
Old
Profile PM WWW Search
Demosthenes seldom sees opportunities until they cease to beDemosthenes seldom sees opportunities until they cease to beDemosthenes seldom sees opportunities until they cease to beDemosthenes seldom sees opportunities until they cease to be
 
Demosthenes