# integers to roman numerals(beginner)

• 03-31-2007
FragileWarning1
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; }```
• 03-31-2007
h_howee
Code:

`if (numbers < 1 || numbers > 3999)`
what you have is: if number is less than 1 OR greater than 3999
• 03-31-2007
Daved
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.