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 6747159
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:24:32+00:00 2026-05-26T12:24:32+00:00

Problem 17 on project euler states: If the numbers 1 to 5 are written

  • 0

Problem 17 on project euler states:

If the numbers 1 to 5 are written out in words: one, two, three, four, five, then there are 3 + 3 + 5 + 4 + 4 = 19 letters used in total.
If all the numbers from 1 to 1000 (one thousand) inclusive were written out in words, how many letters would be used?
NOTE: Do not count spaces or hyphens. For example, 342 (three hundred and forty-two) contains 23 letters and 115 (one hundred and fifteen) contains 20 letters. The use of “and” when writing out numbers is in compliance with British usage.

I have looked over my code many times and cant find why it isn’t solving it correctly, any help would be greatly appreciated, thanks

`#include <iostream>
#include <sstream>

unsigned int value = 11;//one thousand = 11

short small(short x);
void two(short third);

int main()
{
    for(short count = 0;count<10;count++)
    {
        two(count);
    }
   std::cout<<value;
    std::cin.get();
    return 0;
}

void two(short third)
{

    std::string temp;
    if(third>0)
    {
         third = (small(third) + 10);//10 = and(3) + hundred(7)
    }
    for(short i = 0;i<20;i++)//0-20
    {   
        value += (small(i) + third);      
    }
    for(short i = 20;i<60;i++)//20-40 + 80-100
    {
         std::stringstream ss;
         ss<<i;
         temp = ss.str();
         value += ((small(temp[1]-'0') + 6) + third);
    }
    for(short i = 40;i<70;i++)//40-70
    {
         std::stringstream ss;
         ss<<i;
         temp = ss.str();
         value += ((small(temp[1]-'0') + 5) + third);
    }
    for(short i = 70;i<80;i++)//70-80
    {
         std::stringstream ss;
         ss<<i;
         temp = ss.str();
         value += ((small(temp[1]-'0') + 7) + third);
    }      
}

short small(short x)
{
              switch(x)
             {
                case 0:
                     return 0;
                case 1:
                     return 3;
                case 2:  
                     return 3;
                case 3:
                     return 5;
                case 4:
                     return 4;
                case 5:
                     return 4;
                case 6:
                     return 3;
                case 7:
                     return 5;
                case 8:
                     return 5;
                case 9:
                     return 4;
                case 10:
                     return 3;
                case 11:
                     return 6;
                case 12:
                     return 6;
                case 13:
                     return 8;
                case 14:
                     return 8;
                case 15:
                     return 7;
                case 16:
                     return 7;
                case 17:
                     return 9;
                case 18:
                     return 8;
                case 19:
                     return 8;                   
          }
}
  • 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-26T12:24:33+00:00Added an answer on May 26, 2026 at 12:24 pm

    First you need to consider John Mashall’s answer. The solution using strings is not optimal, you might consider extract the second digit using modulus 10 instead.

    You aren’t adding the round hundreds 100, 200, 300, 400, … you add 101, 102, … correctly but not the round hundreds. Inside your code that add the initial and hundred (10 characters) you should also add the length of hundred (7) (and one, two, thee, …) to the value:

    if(third>0)
    {
         third = (small(third) + 10);//10 = and(3) + hundred(7)
         value += third - 3; // no need for the "and"
    }
    

    If I apply John Marshalls fix (using modulus instead) and apply the above I get the correct result of (hover mouse over box below to see result):

    21124

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

Sidebar

Related Questions

I'm working on Project Euler problem number 205 which states: Peter has nine four-sided
I'm working on problem four of Project Euler and am running into a stackoverflow
Some of you may recognize this as Project Euler's problem number 11. The one
So on Project Euler the Problem 4 states the following: A palindromic number reads
This is Problem 3 from Project Euler site I'm not out after the solution,
Project Euler problem 36 states: The decimal number, 585 = 1001001001 (binary), is palindromic
I am trying to solve Project Euler problem #12: The sequence of triangle numbers
I have a code that basically solves one of the problem in Project Euler
In a Project Euler problem I need to deal with numbers that can have
I have this code written for a Project Euler problem in c++: int sum

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.