integers to roman numerals(beginner)

This is a discussion on integers to roman numerals(beginner) within the C++ Programming forums, part of the General Programming Boards category; I'm having some trouble with a program that is suppose to convert integers to roman numerals. It's school work so ...

  1. #1
    Registered User
    Join Date
    Mar 2007
    Posts
    1

    integers to roman numerals(beginner)

    I'm having some trouble with a program that is suppose to convert integers to roman numerals. It's school work so i want to avoid asking for to much information but the thing that is causing the trouble is the outputs. It is suppose to display and error message if anything below 1 is entered or above 3,999 which it does, but it will also print the message that is suppose to be printed if the number entered fits in the boundries. I'm thinking i have done something wrong with the functions which i am not very familiar with but they need to be used if anyone any information that could help that would be great. PS: The cout statment in the ConvertToRoman function is just there as a placeholder/tester for me since i do not know how i am going to convert the int to roman numeral yet...anywhere here's what i have

    Code:
    #include <iostream>
    #include <string>
    using namespace std;
    
    /****************Function Prototypes****************/
    
    int GetTheNumber(int);
    void ConvertToRoman(int, string);
    void PrintResults(int, string);
    
    /**************************************************/
    
    int main()
    {
    
    	int numbers = 0;
    	string roman;
    	char again;
    
    	GetTheNumber(numbers);
    
    
    	do
    	{
    
    	if (numbers < 1 || numbers > 3999)
    		cout << "Cannot convert that number: out of range" << endl;
    
    	else
    	{
    		
    		ConvertToRoman(numbers, roman);
     	}
    
    	PrintResults(numbers, roman);
    
    	cout << "Would you like to enter another year? ";
    	cin >> again;
    	cout << endl;
    
    	}while(again == 'y');
    		
    		return 0;
    	}
    
    int GetTheNumber(int numbers)
    {
    		cout << "Enter a number between 1 and 3,999: ";
    		cin >> numbers;
    		cout << endl;
    		return numbers;
    }
    
    void ConvertToRoman(int numbers,string roman)
    {
    	
    	if (numbers = 1000)
    		roman = "M";
    	else 
    		cout << "wrong";
    
    	
    	return;
    }
    
    void PrintResults(int numbers,string roman)
    {
    
    	cout << "The roman equivilent of " << numbers << " is: " << roman << endl;
    
    	return;
    }

  2. #2
    Registered User
    Join Date
    Dec 2005
    Location
    Canada
    Posts
    267
    Code:
    if (numbers < 1 || numbers > 3999)
    what you have is: if number is less than 1 OR greater than 3999

    OS: Windows 7, XUbuntu 11.10, Arch Linux
    IDE: CodeBlocks
    Compiler: GCC

  3. #3
    Registered User
    Join Date
    Jan 2005
    Posts
    7,319
    Just follow the flow. Your if statement is correct, and if the numberis out of range it prints the error. Then it continues with the program after the else block. The next statement after the else block is PrintResults(numbers, roman); so that is called.

    Whatever code you don't want to run should be placed inside the else block.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Link List math
    By t014y in forum C Programming
    Replies: 17
    Last Post: 02-20-2009, 05:55 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. Replies: 6
    Last Post: 08-04-2003, 10:57 AM

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