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

  • Home
  • SEARCH
  • 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 7050647
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:10:07+00:00 2026-05-28T03:10:07+00:00

I am getting a wrong answer when I wrote a code to solve Prob

  • 0

I am getting a wrong answer when I wrote a code to solve Prob 17 in Project Euler.
I am outputting every string to make the count more clear.

The link is posted here: http://codepad.org/wE54t7Qi

Can someone help me to determine where the problem is?

map<long int, string> CharNumberValue;

int main()
{

CharNumberValue[0] ="zero";
CharNumberValue[1] ="one";
CharNumberValue[2] ="two";
CharNumberValue[3] ="three";
CharNumberValue[4] ="four";
CharNumberValue[5] ="five";
CharNumberValue[6] ="six";
CharNumberValue[7] ="seven";
CharNumberValue[8] ="eight";
CharNumberValue[9] ="nine";
CharNumberValue[10] ="ten";
CharNumberValue[11] ="eleven";
CharNumberValue[12] ="twelve";
CharNumberValue[13] ="thirteen";
CharNumberValue[14] ="fourteen";
CharNumberValue[15] ="fifteen";
CharNumberValue[16] ="sixteen";
CharNumberValue[17] ="seventeen";
CharNumberValue[18] ="eighteen";
CharNumberValue[19] ="nineteen";
CharNumberValue[20] ="twenty";
CharNumberValue[30] ="thirty";
CharNumberValue[40] ="forty";
CharNumberValue[50] ="fifty";
CharNumberValue[60] ="sixty";
CharNumberValue[70] ="seventy";
CharNumberValue[80] ="eighty";
CharNumberValue[90] ="ninety";
CharNumberValue[100] ="hundred";//Sameer,remember 100 is one hundred
CharNumberValue[1000] ="thousand";//Sameer,remember 1000 is one thousand

  long int count = 0; 
  string printword ="";

for(int i=1; i< 1000; i++)
{

    if(i<=100)
    {
        int ten = (i/10)*10;
        int unit = i%10;    
        map<long int, string>:: iterator it = CharNumberValue.find(i);
        map<long int, string>:: iterator it1 = CharNumberValue.find(unit);
        map<long int, string>:: iterator it2 = CharNumberValue.find(ten);

        if(i<10)
        {
            count  += it1->second.length();
            printword = it1->second;
            cout<<printword<<endl;
        }
        if(i>=10 && i<=20)
        {
            count  += it->second.length();//These are unique
            printword = it->second;
            cout<<printword<<endl;
        }
        if(i>20 && i<=100) 
        {

            count  += it2->second.length();
            printword = it2->second ;
            if ((i != 30)&&(i != 40)&&(i != 50)&&(i != 60)&&(i != 70)&&(i != 80)&&(i!= 90)&&(i!= 100))
            {
                count  += it1->second.length();
                printword = it2->second + " " + it1->second ;

            }
            cout<<printword<<endl;              
        }           

    }
    if(i>100 && i<1000)
    {
        int hun = i/100;
        int ten=i%100;
        int mten = (ten/10)*10;//modified ten
        int unit = ten%10;

        map<long int, string>:: iterator it = CharNumberValue.find(unit);
        map<long int, string>:: iterator it1 = CharNumberValue.find(mten);          
        map<long int, string>:: iterator it2 = CharNumberValue.find(ten);
        map<long int, string>:: iterator it3 = CharNumberValue.find(hun);           
        int counttemp = CharNumberValue[100].length();
        count  += it3->second.length() + CharNumberValue[100].length();
        printword = it3->second + " " + CharNumberValue[100];

        if((i != 200)&&(i != 300)&&(i != 400)&&(i != 500)&&(i != 600)&&(i != 700)&&(i != 800)&&(i != 900))
        {
            if( ten<=20)
            {
                count  += 3/*for and */+ it2->second.length()   ;//These are unique
                printword = it3->second + " " + CharNumberValue[100]  + " and "  + it2->second ;
                cout<<printword<<endl;
            }

            if(ten>20 && ten<=99) 
            {
                count  += 3/*for and */+ it1->second.length();
                printword = it3->second + " " + CharNumberValue[100]  + " and "  + it1->second;
                if ((ten != 30)&&(ten != 40)&&(ten != 50)&&(ten != 60)&&(ten != 70)&&(ten != 80)&&(ten!= 90)&&(ten!= 100))
                {
                    count  += it->second.length();
                    printword = it3->second + " " + CharNumberValue[100]  + " and "  + it1->second +" "+ it->second ;
                }

                cout<<printword<<endl;
            }

        }
        else
        {
            cout<<printword<<endl;
        }
    }
}
count += 11;//for one thousand
cout<< count;

return 0;
}
  • 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-05-28T03:10:08+00:00Added an answer on May 28, 2026 at 3:10 am

    You’re outputting “hundred” instead of “one hundred”.

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

Sidebar

Related Questions

I am trying to multiply two strings, but I am getting the wrong answer.
I am getting a Wrong type argument: commandp, (lambda nil (forward-line 5)) here. (global-set-key
I am getting a wrong output when i alert this, it shows '01' <input
I have a jboss web service that is getting the wrong initial context. I
I'm getting a NoSuchMethodError error when running my Java program. What's wrong and how
new Date(05-MAY-09 03.55.50) is any thing wrong with this ? i am getting illegalArgumentException
Hey! Maybe I am getting the idea of a subclass wrong, but I have
I'm trying to create a rails app, but somethings going wrong, I'm getting a
I'm learning python, so I'm going through some Project Euler problems. I'm not sure
My last question was a mess. I'm getting the wrong output. So here I

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.