Roman Numeral Generator

Hello all! So as you can read in some previous posts I have been working on a roman numeral ID method for my Simpossible game. The code is now finished! Previous posts were only inclusive up to the roman numeral for 20 but now it is complete, including numerals all the way up to 100! It took a while to perfect the method, but ALAS it is complete! I had lots of fun with this specific method as it posed some very interesting challenges utilizing the modulus operation. Ill paste the code and some output below! Enjoy!

    // Difficulty above 6
    else if(difficulty > 6){
        
        // Seeds and initializes random number
        srand(time(0));
        int randomNum = rand() % 100 + 10;
        
        // Checks for base 50
        if((randomNum % 50) == 0){
            
            // Creates string for as many times as 50 goes into the number
            for(int rep = 0; rep < (randomNum/50); rep++){
                
                // Adds L to the string
                number += "L";
                
                // If the repetition is 1, the string will be cleared and "C" will be put instead
                if(rep == 1){
                    number.clear();
                    number += "C";
                }
                
            }
            
            // Outputs the number and takes in user's answer
            cout << number << endl;
            
            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;
                
            }
            
        }
        
        // Checks to see if random number is less than 40
        else if(randomNum < 40){
            
            // Creates loop to iterate as many times as 10 goes into the random number
            for(int rep = 0; rep < randomNum/10; rep++){
                
                // adds an X to the string for each iteration
                number += "X";
            }
            
            // If the number is 1 unit away from a base (aka 19, 29, 39)
            if(((randomNum + 1) % 10) == 0){
                number += "IX";
            }
            
            // If the number ends in a 5
            else if((randomNum % 5) == 0){
                number += "V";
            }
            
            // If the number ends in 6, 7, or 8
            else if(((randomNum % 5) < 4) && ((randomNum % 10) > 5)){
                number += "V";
                
                // A loop that iterates for each remaining value when random is divided by 5
                for(int rep = 0; rep < (randomNum % 5); rep++){
                    
                    // Appends an I for each iteration
                    number += "I";
                }
            }
            
            // If the number ends in a 4
            else if(((randomNum + 1) % 5) == 0){
                number += "IV";
                
            }
            
            // Oterwise, just adds Is for each unit random is above a base 10
            else {
                
              
                // Loop that iterates for each value that random number is above 10
                for(int rep = 0; rep < (randomNum % 10); rep++){
                    
                    // Appends an I to the string
                    number += "I";
                }
                
            }
            
            // Outputs numeral and takes user's input
            cout << number << endl;
            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 random is greater than 40 & less than 50
        else if(randomNum >= 40 && randomNum < 50){
            
            // Creates 49 in numerals if number is 49.. How whack is it that that's 49..!
            if(randomNum == 49){
                
                 number += "XLIX";
            }
            
            // Creates 40 in numerals
            else{
                
                number += "XL";
                
                // Appends a V if the number requires
                if((randomNum - 40) >= 5){
                    number += "V";
                }
                
                // Adds Is for amount or remainder when divided by 5
                for(int rep = 0; rep < (randomNum % 5); rep++){
                    
                    number += "I";
                }
            }
            
            // Outputs numeral and recieves users input
            cout << number << endl;
            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;

                
            }
            
            
            
        }
        
        
        // Checks to see if random number is greater than 50
        else if(randomNum > 50 && randomNum < 90){
            
            number += "L";
            
            // Creates loop to iterate as many times as 10 goes into the random number
            for(int rep = 0; rep < randomNum/10; rep++){
                
                // adds an X to the string for each iteration
                number += "X";
            }
            
            // If the number is 1 unti away from a base (aka 19, 29, 39)
            if(((randomNum + 1) % 10) == 0){
                number += "IX";
            }
            
            // If the number ends in a 5
            else if((randomNum % 5) == 0){
                number += "V";
            }
            
            // If the number ends in 6, 7, or 8
            else if((randomNum % 5) < 4){
                number += "V";
                
                // A loop that iterates for each remaining value when random is divided by 5
                for(int rep = 0; rep < (randomNum % 5); rep++){
                    
                    // Appends an I for each iteration
                    number += "I";
                }
            }
            
            // If the number ends in a 4
            else if(((randomNum + 1) % 5) == 0){
                number += "IV";
                
            }
            
            // Otherwise, just adds Is for each unit random is above a base 10
            else {
                
                
                // Loop that iterates for each value that random number is above 10
                for(int rep = 0; rep < (randomNum % 10); rep++){
                    
                    // Appends an I to the string
                    number += "I";
                }
                
            }
            
            // Outputs numeral and takes user's input
            cout << number << endl;
            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 number is between 90 and 100
        else{
            
           
            // Creates 99 in numerals if number is 99.. How whack is it that that's 99..!
            if(randomNum == 99){
                
                number += "XCIX";
            }
            
            // Creates 90 in numerals
            else{
                
                number += "XC";
                
                // Appends a V if the number requires
                if((randomNum - 90) >= 5){
                    number += "V";
                }
                
                // Adds Is for amount or remainder when divided by 5
                for(int rep = 0; rep < (randomNum % 5); rep++){
                    
                    number += "I";
                }
            }
            
            // Outputs numeral and recieves users input
            cout << number << endl;
            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;
}


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s