C++ Program

I am trying to create a program that displays the roman numeral equivalent of any decimal number between 1 and 20 that the user enters. The roman numerals should be stored in an array of strings and the decimal number that the user enters should be used to locate the array element holding the roman numeral equivalent. The program should have a loop that allows the user to continue entering numbers until and end sentinal is entered ..Input validation- do not accept scores less than 0 or greater than 20.
I have looked up this answer and I don't see anything that will help me, here is my code:
/*This program will display the roman numeral equivalent of any decimal number between 1 and 20
that the user enters. The roman numerals should be stored in an array of strings and the decimal
number that the user enters should be used to locate the array element holding the roman numeral
equivalent. The program should have a loop that allows the user to continue entering numbers
until an end sentinel of 0 is entered.*/

#include <iostream>
#include <string>
using namespace std;

int main()
{
const int ROMAN_NUM = 21; //Size of the elements in the array
const int SENTINEL = 0; //Variable stays 0 during entire program
int num = 1; //Variable to store user input, initialized to non-zero for error test

//Roman numerals stored in an array
string roman[ROMAN_NUM] = { "", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX", "X",
"XI", "XII", "XIII", "XIV", "XV", "XVI", "XVII", "XIII", "XIX", "XX"}


}

}
I am having trouble with the next step, do I ask the user to enter a number and then validate it and create the loop?
The question clearly tells you that you need to get the user to input the number.

The question clearly tells you that you need to validate the number the user inputs.

Now think about your loop. Do you want the user to input the number inside the loop, or outside it? Do you want to validate the input inside the loop, or outside it?

You need to think logically about the things you want your program to do. Once you've done that, then you can start thinking about the actual lines of code.
okay I have finished the code but I can't figure out what the error message means. Here is the code maybe you can run it and tell me what the error messages mean:

/*This program will display the roman numeral equivalent of any decimal number between 1 and 20
that the user enters. The roman numerals should be stored in an array of strings and the decimal
number that the user enters should be used to locate the array element holding the roman numeral
equivalent. The program should have a loop that allows the user to continue entering numbers
until an end sentinel of 0 is entered.*/

#include <iostream>
#include <string>
using namespace std;

int main()
{
const int ROMAN_NUM = 21; //Size of the elements in the array
const int SENTINEL = 0; //Variable stays 0 during entire program
int num = 1; //Variable to store user input, initialized to non-zero for error test

//Roman numerals stored in an array
string roman[ROMAN_NUM] = { "", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX", "X",
"XI", "XII", "XIII", "XIV", "XV", "XVI", "XVII", "XIII", "XIX", "XX" };
do
{
cout << "Please enter a number between 1 and 20 " << roman[ROMAN_NUM] - 1 << " (Enter 0 to stop): ";
if (!(cin >> num))
{
cout << "Entry is not a number" << endl;
cin.clear();
cin.ignore(100, '\n');
}
else
if (num > 0 && num < roman[ROMAN_NUM])
cout << num << " is equivalent to " << roman[ROMAN_NUM] << endl
else
if (num != SENTINEL)
cout << "Invalid number\n";
}
cin.get();
cin.get();
return roman;

}
Last edited on
There are... Quite a few errors there... I don't even...
You should use [ code ] when you send code.
Topic archived. No new replies allowed.