Thread: Roman Numeral^^

  1. #1
    Registered User
    Join Date
    Apr 2007
    Posts
    15

    Roman Numeral^^

    haha thnx to u guys i got this thing to work but there is a one problem

    i dont know how to change 4 to IV

    when i type 4 it comes out like IIII

    4,9,40,90 ....

    Code:
    while (x != 0)
    	if (x >= 1000)
    	{
    		x = x - 1000;
    		cout << "M";
    	}
    	else if (x >= 500)
    	{
    		x = x - 500;
    		cout << "D";
    	{
    	else if (x >= 100)
    	{
    		x = x - 100;
    		cout << "C";
    	{
    	else if (x > 50)
    	{
    		x = x-50;
    		cout << "L";
    	}
    	else if (x >= 10)
    	{
    		x = x - 10;
    		cout << "X";
    	}
    	else if (x >= 5)
    	{
    		x = x - 5;
    		cout << "V";
    	}
    	else if (x >= 1)
    	{
    		x = x - 1;
    		cout << "I";
    	}
    }

  2. #2
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by only1st View Post
    when i type 4 it comes out like IIII
    Well obviously, considering your code doesn't look for 4, or 8, or 9, or any of the other special cases.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    4 and 9 are also special.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    Registered User
    Join Date
    Apr 2007
    Posts
    15
    yes i didnt put it in my code cause i dont know... so can u guys give me some ideas? plzzzzz

  5. #5
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    This is why it would be better to write out your algorithm in english first, before you start coding. That way you can see holes in your implementation even before you start.

    Forget a C++ program, how would you do the conversion in your head or with paper? How would you do it with 4? How about 9? And how about 79? Once you write that out in english, and maybe even post it here, we can help further.

  6. #6
    Registered User
    Join Date
    Apr 2007
    Posts
    15
    oh ok daved ty^^ ill try it

  7. #7
    Registered User
    Join Date
    Apr 2007
    Posts
    15
    haha thanx to u guys i finally finished my program once agin thnx

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Roman Numeral troubles....
    By h4rrison.james in forum C Programming
    Replies: 16
    Last Post: 01-15-2009, 09:26 PM
  2. roman numeral conversion
    By clarky101 in forum C Programming
    Replies: 8
    Last Post: 12-09-2007, 07:13 PM
  3. Replies: 3
    Last Post: 08-21-2006, 06:42 AM
  4. Using loops for check a roman number input.
    By eryell in forum C++ Programming
    Replies: 9
    Last Post: 04-12-2006, 11:04 AM
  5. implicit declatation of function 'int toupper(...)'
    By Intimd8r in forum C Programming
    Replies: 3
    Last Post: 10-01-2001, 02:43 PM