Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 136,163 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,886 people online right now. Registration is fast and FREE... Join Now!




Roman To Arabic HELP!

 
Reply to this topicStart new topic

Roman To Arabic HELP!, struggling to understand why some simple code wont work!!!

spikes135
7 Dec, 2007 - 03:55 AM
Post #1

New D.I.C Head
*

Joined: 7 Dec, 2007
Posts: 1


My Contributions
CODE
#include <stdio.h>
void main()
{

//declaring function variables
char RomanNumeral[20]; //this is the array of 20 charactors
int locationcounter; //the counter that goes through the loacations in the array
int Arabicvalue; //this is the converted arabic value


//body of function
printf("Enter Roman Numeral \n");//asks user to enter a roman numeral
scanf("%s", &RomanNumeral[0]); // reads the string and stores it into the array
printf("\n\n %s", RomanNumeral);




for (locationcounter=0; locationcounter <19; locationcounter++)//this loop looks at each location in the array

{
if (RomanNumeral[locationcounter]=='I')
    Arabicvalue +=1;

else if (RomanNumeral[locationcounter]=='V')
{
if (RomanNumeral[locationcounter-1]=='I')
    Arabicvalue +=3;
else
    Arabicvalue +=5;

}



else if (RomanNumeral[locationcounter]=='X')
{
    if (RomanNumeral[locationcounter-1]=='I')
    Arabicvalue +=8;

else if (RomanNumeral[locationcounter]=='V')
    Arabicvalue +=0;

else
    Arabicvalue +=10;
}



else if (RomanNumeral[locationcounter]=='L')
{
if (RomanNumeral[locationcounter-1]=='I')
    Arabicvalue +=48;

else if (RomanNumeral[locationcounter]=='V')
    Arabicvalue +=40;

else if (RomanNumeral[locationcounter]=='X')
    Arabicvalue +=30;

else
    Arabicvalue +=50;
}



else if (RomanNumeral[locationcounter]=='C')
{
if (RomanNumeral[locationcounter-1]=='I')
    Arabicvalue +=98;

else if (RomanNumeral[locationcounter]=='V')
    Arabicvalue +=90;

else if (RomanNumeral[locationcounter]=='X')
    Arabicvalue +=80;

else if (RomanNumeral[locationcounter]=='L')
    Arabicvalue +=0;

else
    Arabicvalue +=100;
}




else if (RomanNumeral[locationcounter]=='D')
{
if (RomanNumeral[locationcounter-1]=='I')
    Arabicvalue +=498;

else if (RomanNumeral[locationcounter]=='V')
    Arabicvalue +=490;

else if (RomanNumeral[locationcounter]=='X')
    Arabicvalue +=480;

else if (RomanNumeral[locationcounter]=='L')
    Arabicvalue +=400;

else if (RomanNumeral[locationcounter]=='C')
    Arabicvalue +=300;

else
    Arabicvalue +=500;
}


else if (RomanNumeral[locationcounter]=='M')
{
if (RomanNumeral[locationcounter-1]=='I')
    Arabicvalue +=998;

else if (RomanNumeral[locationcounter]=='V')
    Arabicvalue +=990;

else if (RomanNumeral[locationcounter]=='X')
    Arabicvalue +=980;

else if (RomanNumeral[locationcounter]=='L')
    Arabicvalue +=900;

else if (RomanNumeral[locationcounter]=='C')
    Arabicvalue +=800;

else if (RomanNumeral[locationcounter]=='D')
    Arabicvalue +=0;

else
    Arabicvalue +=1000;
}
}

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

}

User is offlineProfile CardPM
+Quote Post

Trogdor
RE: Roman To Arabic HELP!
7 Dec, 2007 - 05:02 AM
Post #2

D.I.C Addict
Group Icon

Joined: 6 Oct, 2006
Posts: 523



Thanked: 3 times
Dream Kudos: 125
My Contributions
and what do you expect from us now?
User is offlineProfile CardPM
+Quote Post

no2pencil
RE: Roman To Arabic HELP!
7 Dec, 2007 - 05:07 AM
Post #3

My fridge be runnin OH NOEZ!
Group Icon

Joined: 10 May, 2007
Posts: 6,446



Thanked: 66 times
Dream Kudos: 2425
Expert In: Goofing Off

My Contributions
CODE

char RomanNumeral[20]; //this is the array of 20 charactors
                                     // True, this creates an array of 20 characters.

//body of function
printf("Enter Roman Numeral \n");//asks user to enter a roman numeral
scanf("%s", &RomanNumeral[0]); // reads the string and stores it into the array
                                                 // no.  


This reads a string & stores it into the 1st element of your array. If RomanNumberal contains a string of "Hello World" then RomanNumberal[0] = the letter 'H'
User is online!Profile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/1/08 11:55PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month