Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8988647
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T22:03:11+00:00 2026-06-15T22:03:11+00:00

string scriviNumeroMinoreMille(int a) { vector<string> v_zero_to_nineteen(20); vector<string> v_twenty_to_ninety(8); v_zero_to_nineteen = {zero, uno, due, tre,

  • 0
string scriviNumeroMinoreMille(int a)
{
    vector<string> v_zero_to_nineteen(20);
    vector<string> v_twenty_to_ninety(8);

    v_zero_to_nineteen = {"zero", "uno", "due", "tre", "quattro", "cinque", "sei", "sette", "otto", "nove", "dieci", "undici",
                          "dodici", "tredici", "quattordici", "quindici", "sedici", "diciassette", "diciotto", "diciannove"};

    v_twenty_to_ninety = {"venti", "trenta", "quaranta", "cinquanta", "sessanta", "settanta", "ottanta", "novanta"};

    string risultato;

    if(a == 0)
    {
        return risultato = "";
    }
    else if(a < 20 && a > 0)
    {
        return risultato = v_zero_to_nineteen[a];
    }
    else if(a == 20 || a == 30 || a == 40 || a == 50 || a == 60 || a == 70 || a == 80 || a == 90)
    {
        return risultato = v_twenty_to_ninety[(a/10)-2];
    }
    else if(a == 100)
    {
        return risultato = "cento";
    }

    int unita = 0;
    int decine = 0;
    int centinaia = 0;

    if(a > 99)
    {
        centinaia = a/100;
        risultato += (v_zero_to_nineteen[centinaia]);
        risultato += "cento";
    }
    if(a > 19)
    {
        if(a-(centinaia*100)%10 == 0)
        {
            decine = (a-(centinaia*100))/10;
            risultato += (v_twenty_to_ninety[decine-2]);
        }
        else
        {
            decine = (a-(centinaia*100)/10);
            risultato += v_twenty_to_ninety[decine-2];
            unita = (a-(centinaia*100)-(decine*10));
            risultato += v_zero_to_nineteen[unita];
        }
    }
    return risultato;
}

I made this function to check a number from 0 to 999 to convert a number in a string. The result would be for example if the input is 100, the output would be “one hundred” (it’s translated in italian)

I don’t understand why in debugging the arguments inside these two if clauses:

if(a > 99)
{
    centinaia = a/100;
    risultato += (v_zero_to_nineteen[centinaia]);
    risultato += "cento";
}
if(a > 19)
{
    if(a-(centinaia*100)%10 == 0)
    {
        decine = (a-(centinaia*100))/10;
        risultato += (v_twenty_to_ninety[decine-2]);
    }
    else
    {
        decine = (a-(centinaia*100)/10);
        risultato += v_twenty_to_ninety[decine-2];
        unita = (a-(centinaia*100)-(decine*10));
        risultato += v_zero_to_nineteen[unita];
    }
}

are not considered in the function. Those two ifs are just skipped. I don’t understand why. If I put 123 as the input those ifs are skipped. But the condition is if(a > 99), 120 is more than 99. I don’t understand.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T22:03:12+00:00Added an answer on June 15, 2026 at 10:03 pm

    there are several errors in your code:

    First the += operator of the string type takes a “const string&”, so instead of doing this:

    risultato += (v_twenty_to_ninety[decine-2])
    

    you need to pass it like this:

    risultato += v_twenty_to_ninety[decine-2].c_str();
    

    also here

    decine = (a-(centinaia*100)/10);
    

    you are using “centinaia” which at this point is zero because you only made the calculation inside the if(a > 99) if block and also the /10 should be outside the parentesis like this:

    decine = (a-(centinaia*100))/10
    

    So you need to move this centinaia = a/100; outside the if, so all 3 if statement gets the calculated variable (same with the other two).

    this:

    int unita = 0;
    int decine = 0;
    int centinaia = a/100;
    

    to this:

    int centinaia = a/100;
    int decine    = (a-(centinaia*100))/10;
    int unita     = (a-(centinaia*100)-(decine*10));
    

    I made this changes to your method, It now look like this:

    string scriviNumeroMinoreMille(int a)
    {
        vector<string> v_zero_to_nineteen(20);
        vector<string> v_twenty_to_ninety(8);
    
        v_zero_to_nineteen = {"zero", "uno", "due", "tre", "quattro", "cinque", "sei", "sette", "otto", "nove", "dieci", "undici",
                              "dodici", "tredici", "quattordici", "quindici", "sedici", "diciassette", "diciotto", "diciannove"};
    
        v_twenty_to_ninety = {"venti", "trenta", "quaranta", "cinquanta", "sessanta", "settanta", "ottanta", "novanta"};
    
        string risultato;
    
        if(a == 0)
        {
            return risultato = "";
        }
        else if(a < 20 && a > 0)
        {
            return risultato = v_zero_to_nineteen[a];
        }
        else if(a == 20 || a == 30 || a == 40 || a == 50 || a == 60 || a == 70 || a == 80 || a == 90)
        {
            return risultato = v_twenty_to_ninety[(a/10)-2];
        }
        else if(a == 100)
        {
            return risultato = "cento";
        }
    
        int centinaia = a/100;
        int decine    = (a-(centinaia*100))/10;
        int unita     = (a-(centinaia*100)-(decine*10));
    
        if(a > 99)
        {
    
           risultato += v_zero_to_nineteen[centinaia].c_str();
           risultato += "cento";
    
    
        }
        if(a > 19)
        {
            if(a-(centinaia*100)%10 == 0)
            {
                risultato += v_twenty_to_ninety[decine-2].c_str();
            }
            else
            {
                risultato += v_twenty_to_ninety[decine-2].c_str();
    
                risultato += v_zero_to_nineteen[unita].c_str();
            }
        }
        return risultato;
    }
    

    For the 123 input it outputs “unocentoventitre”, I dont know if thats correct since I dont speak italian xD

    Hope it helps.

    EDIT: forgot to remove/change back the lines I inserted for testing.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

string abc = 07:00 - 19:00 x = int.Parse(only first two characters) // should
String[] tokens = s.split(' '); for(int i = 0; i < (tokens.length) - 1;
string sql=, sql2 = , rank=; int basic_wage, rent_allowance, seniority_allowance, overtime_rate; sql += select
String[] S1 = miscParams.Split(;.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < S1.Count(); )
string sequence = 12345; int[] ziffern = new int[sequence.Count()]; for (int i = 0;
String input from keyboard Vector<String> myVector = new Vector<String>(someArray.length); //assume Vector is populated Iterator<String>
string separator = > ; string retStr = ; int count = 0; foreach
string value1 , value1 ; int length1 , length2 ; System.Collections.BitArray bitValue1 = new
String[] names=new String[4]; int[] scores=new int[4]; Scanner keyboard = new Scanner(System.in); System.out.println(Enter 4 strings
string a = sea; string b = SEA if (a == b)... How could

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.