Converting a number into a word (Not 0 to zero)

Hello, I'm very new to C++, only on my second month of learning it.

I'm trying to create a program that can basically take a barcode number like "3343456" and turn it into something like "Chiquita® Brand Bananas". I've tried using examples of C++ code I've found on google and this site but can't get it to work. I'm using Eclipse and a Linux based computer.

Can anyone help me with this?
Thanks
At some level you'll need to map from this number to a your descritive text.

In the real world you'll want to do this just once. That means someone has to specify the code and text and it needs to be stored for later retrieval. This means writing it to a database. Later on you'd ask the database to do the lookup for you.

If you want to do this in a sample program, you can have the program store this relationship in memory. The C++ Standard Template Library was a number of containers you can use. The most suitable at this stage seems to be a dictionary.

So it depends what you want to do.
How would you store data for later retrieval, I'm trying to set the data up into Arrays for easy storage but I'm having some trouble. here's what I have so far:



#include <iostream>


using namespace std;
int main ()
{
int Number;
int item;
string arrayOfIntegers [item] ;

cout << "Please enter a number ";
cin >>Number;



item = 2;
arrayOfIntegers[0] = "Chiquita Brand Bananas";
arrayOfIntegers[1] = "Gala Brand Apples";


if (Number == 3453456)
{
cout << arrayOfIntegers[0] << endl;
}
else if (Number == 34534567)
{
cout << arrayOfIntegers[1] << endl;
}







return 0;
}
You need to declare item higher up in the program. Before you set item to 2, it starts out at zero like all variables. The Array "arrayOfIntegers" only sees that item is 0 at the moment, and creates an array of 0 strings. Once you set item to 2 its already to late, you would want to move item up above the declaration of your array. And just for saftey purposes, you might want to add in const int item = 2; so that you don't accidentally change item. Hope this helps
Topic archived. No new replies allowed.