Roman Numeral^^

This is a discussion on Roman Numeral^^ within the C++ Programming forums, part of the General Programming Boards category; haha thnx to u guys i got this thing to work but there is a one problem i dont know ...

  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
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,235
    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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,434
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  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,317
    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, 08:26 PM
  2. roman numeral conversion
    By clarky101 in forum C Programming
    Replies: 8
    Last Post: 12-09-2007, 06: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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21