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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T20:52:31+00:00 2026-05-13T20:52:31+00:00

I’m working on a program for class that takes in a number from 0

  • 0

I’m working on a program for class that takes in a number from 0 to 9999, and spits out the word value (ie 13 would be spit out as “thirteen”, etc) And I’m having a pain with the array for some reason.

Here is the class so far:

#include<iostream>
#include<string>

using namespace std;

class Numbers
{
    private:

        int number;

        string lessThan20[ ] = {"zero", "one", "two", "three", "four", "five", 
            "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", 
            "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen"};
        string incrementsOfTen[ ] = {"twenty", "thirty", "fourty", "fifty", "sixty",
            "seventy", "eighty", "ninety"};
        string hundred = "hundred";
        string thousand = "thousand";

    public:
        Numbers(int newNumber)
        {
            setNumber(newNumber);
        }

        void setNumber(int newNumber)
        {
            if(newNumber < 0 || newNumber > 9999)
            {
                cout << "Number cannot be negative or larger than 9999, defaulted to zero." << endl;
                number = 0;
            }
            else
            {
                number = newNumber;
            }
        }

        int getNumber()
        {
            return number;
        }
};

My issue is up at the two string arrays, I’m getting these errors back from my compiler:

1>f:\college work\csis 297\assignment 4\chapter 11-1\chapter 11-1\11-1.cpp(19) : error C2059: syntax error : '{'
1>f:\college work\csis 297\assignment 4\chapter 11-1\chapter 11-1\11-1.cpp(19) : error C2334: unexpected token(s) preceding '{'; skipping apparent function body
1>f:\college work\csis 297\assignment 4\chapter 11-1\chapter 11-1\11-1.cpp(22) : error C2059: syntax error : '{'
1>f:\college work\csis 297\assignment 4\chapter 11-1\chapter 11-1\11-1.cpp(22) : error C2334: unexpected token(s) preceding '{'; skipping apparent function body
1>f:\college work\csis 297\assignment 4\chapter 11-1\chapter 11-1\11-1.cpp(24) : error C2864: 'Numbers::hundred' : only static const integral data members can be initialized within a class
1>f:\college work\csis 297\assignment 4\chapter 11-1\chapter 11-1\11-1.cpp(25) : error C2864: 'Numbers::thousand' : only static const integral data members can be initialized within a class

I’m sure if I spend more time on the single variable strings I can figure those out, but I’ve spent the better part of an hour looking up what I’m doing wrong on the two arrays, any advice or information would be appreciated.

Thanks in advance.

PS: No, there is no main, haven’t gotten there yet, my program has a blank main right now as I’m simply trying to get the class to compile error free for now.

EDIT for clarification:

The first two errors are on the first array, the second two errors on the second array, and the last two errors are on the non-array strings.

  • 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-13T20:52:32+00:00Added an answer on May 13, 2026 at 8:52 pm

    The error message says it all:

    only static const integral data members can be initialized within a class

    You cannot do what you want, you have to separate declaration and initialization, and move the initialization either to the constructor, or use a static const, and put the initialization outside the class. This is preferred, since the values don’t actually change, or depend on an instance:

    class Numbers
    {
        private:
            static const string lessThan20[];
            // …
    };
    
    string const Numbers::lessThan20[ ] = {"zero", "one", "two", "three", "four", "five", 
                "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", 
                "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen"};
    

    And analogously for the other array.

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

Sidebar

Related Questions

I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I know there's a lot of other questions out there that deal with this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function

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.