Hello all! So I’ve been working more on my Simpossible game, and specifically on the roman numerals ID minigame I talked about in earlier posts. So, in short, I’ve been working with the modulus operator nonstop for a couple hours… But it’s been really fun! So far, it’s coming together well. The majority of my time I spent on devising just how I would turn regular numbers into roman numerals. I’ve done it mostly by using whats called the “modulus” operator (%). You can read more on that here, but I’ll explain the basis for anyone unfamiliar with programming basics. It’s an operator (Like plus, minus or multiply) which will return the remainder of the first number divided by the second. So, 17 % 5 = 2. This operator is used most frequently in creating bounds for the rand() function, or to find whether or not a number is even.
My use of this operator has been to find whether or not a roman numeral requires an “X” or a “V”. So, for example, I can use the equation 17%10 = 7, and from there determine the appropriate numeral is XVII.
Below is some output and the unfinished method. I hope you enjoy!


/* Roman Numeral ID */ bool romanNumerals(int difficulty){ // Start of game // Initialize roman numeral string to be appended string number; cout << "Hey, ID this Roman Numeral for me.?" << endl; sleep(3); // Difficulties below or equal to 1 if(difficulty <= 1){ // Seed & initialize rand srand(time(0)); int randomNum = rand()% 5; // Ensures rand cant = 0 if (randomNum == 0) randomNum += 3; // If rand is < 4, the numeral will only consist of "I" if(randomNum < 4){ // Create the roman numeral up to 3 for(int rep = 0; rep < randomNum; rep++){ number += "I"; } // Output numeral cout << number << endl; // Take user answer int temp; cin >> temp; // Correct Answer if (temp == randomNum){ cout << endl; } // Wrong Answer else { lives --; cout << incorrectAnswer() << " You have " << lives << " lives left! " << endl << endl; //returns false return false; } } // If rand = 4 else { // Outputs 4 in Roman Numerals cout << "IV" << endl; // Take user answer int temp; cin >> temp; // Correct Answer if(temp == 4){ cout << endl; } // Wrong Answer else{ lives --; cout << incorrectAnswer() << " You have " << lives << " lives left! " << endl << endl; //returns false return false; } } } // Difficulty > 1 && < or equal to 5 else if(difficulty > 1 && difficulty <= 5){ // seeds and initializes rand range 5 - 20 srand(time(0)); int randomNum = rand() % 20 + 6; // Rand = 5 if(randomNum == 9){ // Output cout << "IX" << endl; // User input int temp; cin >> temp; // Correct Answer if (temp == 9){ cout << endl; } // Wrong Answer else{ lives --; cout << incorrectAnswer() << " You have " << lives << " lives left! " << endl << endl; //returns false return false; } } // Rand = 14 else if(randomNum == 14){ // Output cout << "XIV" << endl; // User input int temp; cin >> temp; // Correct Answer if (temp == 14){ cout << endl; } // Wrong Answer else{ lives --; cout << incorrectAnswer() << " You have " << lives << " lives left! " << endl << endl; //returns false return false; } } // Rand = 15 // IDK WHY but this wont work rn else if(randomNum == 15){ // Output cout << "XV" << endl; // User input int temp; cin >> temp; // Correct Answer if (temp == 15){ cout << endl; } // Wrong Answer else{ lives --; cout << incorrectAnswer() << " You have " << lives << " lives left! " << endl << endl; //returns false return false; } } // Rand = 19 else if(randomNum == 19){ // Output cout << "IXX" << endl; // User input int temp; cin >> temp; // Correct Answer if (temp == 19){ cout << endl; } // Wrong Answer else{ lives --; cout << incorrectAnswer() << " You have " << lives << " lives left! " << endl << endl; //returns false return false; } } // Rand = 6 - 20 else{ // If rand is directly divisible by 10 if ((randomNum % 10) == 0){ //Create a string which properly represents rand with Xs for (int rep = 0; rep < (randomNum/10); rep++){ number += "X"; } // Output cout << number << endl; // User input int temp; cin >> temp; // Correct Answer if(temp == randomNum){ cout << endl; } // Wrong Answer else{ lives --; cout << incorrectAnswer() << " You have " << lives << " lives left! " << endl << endl; //returns false return false; } } // If rand can be divided by 10 with a remainder less than 4 else if((randomNum % 10) < 4){ //Starts numeral with a X number += "X"; // Creates the random numeral for(int rep = 0; rep < (randomNum - 10); rep++){ number += "I"; } // Output cout << number << endl; // Input int temp; cin >> temp; // Correct Answer if (temp == randomNum){ cout << endl; } // Wrong Answer else{ lives --; cout << incorrectAnswer() << " You have " << lives << " lives left! " << endl << endl; //returns false return false; } } // If rand can be divided by 10 with a remaineder greater than 5 else if((randomNum % 10) > 5){ // Starts numeral with a XV number += "XV"; // Creates random numeral for(int rep = 0; rep < (randomNum - 15); rep++){ number += "I"; } // Output cout << number << endl; // Input int temp; cin >> temp; // Correct Answer if(temp == randomNum){ cout << endl; } // Wrong Answer else{ lives --; cout << incorrectAnswer() << " You have " << lives << " lives left! " << endl << endl; //returns false return false; } } // If rand is not divisible by 10 at all, aka less than 10 else if(randomNum > 5 && randomNum < 9){ // Starts numeral with a V number += "V"; // Creates the random numeral for(int rep = 0; rep < (randomNum - 5); rep++){ number += "I"; } // Output cout << number << endl; // Input int temp; cin >> temp; // Correct Answer if(temp == randomNum){ cout << endl; } // Wrong Answer else{ lives --; cout << incorrectAnswer() << " You have " << lives << " lives left! " << endl << endl; //returns false return false; } } } } return true; }
One thought on “Roman Numerals ID Method”