letters into numbers problem...

i have a problem when i am trying to change letters into numbers...

Page 1 of 1

3 Replies - 1798 Views - Last Post: 07 April 2007 - 09:24 AM Rate Topic: -----

#1 Tuur  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 16-March 07

letters into numbers problem...

Posted 07 April 2007 - 07:26 AM

Hi , I have a problem.
i am building a program which for i need to be able to switch letters into numbers (a=1, b=2, c=3, d=4 etc)
but when i am running my function, the output is 0 so there didn't changed anything...

here's the code:

 

void convert(void)
{


char message[245];
int numbercode[245];
int x = 0;
int i = 0;
cout<<"Typ the message you want to code:\n ";
cin>> message;
	cout<<"\n\n\n\n`````````````````````````````\message:\n\n";
	cout<< message << endl;
	cout<<"\n`````````````````````````````\n\n\n\n";


 
for ( x = 0; x <245; x++ ) 
{   
	switch (message[x])
	{
	case 'a':
		numbercode[x] = 1;
		break;
	case 'b':
		numbercode[x] = 2;
		break;
	case 'c':
		numbercode[x] = 3;
		break;
	case 'd':
		numbercode[x] = 4;
		break;
	case 'e':
		numbercode[x] = 5;
		break;
	case 'f':
		numbercode[x] = 6;
		break;
	case 'g':
		numbercode[x] = 7;
		break;
	case 'h':
		numbercode[x] = 8;
		break;
	case 'i':
		numbercode[x] = 9;
		break;
	case 'j':
		numbercode[x] = 10;
		break;
	case 'k':
		numbercode[x] = 11;
		break;
	case 'l':
		numbercode[x] = 12;
		break;
	case 'm':
		numbercode[x] = 13;
		break;
	case 'n':
		numbercode[x] = 14;
		break;
	case 'o':
		numbercode[x] = 15;
		break;
	case 'p':
		numbercode[x] = 16;
		break;
	case 'q':
		numbercode[x] = 17;
		break;
	case 'r':
		numbercode[x] = 18;
		break;
	case 's':
		numbercode[x] = 19;
		break;
	case 't':
		numbercode[x] = 20;
		break;
	case 'u':
		numbercode[x] = 21;
		break;
	case 'v':
		numbercode[x] = 22;
		break;
	case 'w':
		numbercode[x] = 23;
		break;
	case 'x':
		numbercode[x] = 24;
		break;
	case 'y':
		numbercode[x] = 25;
		break;
	case 'z':
		numbercode[x] = 26;
		break;
	default:
		numbercode[x] = 0;
		
	}
}



for ( i = 0; i <245; i++ )
{
	cout<<numbercode[x];
	cout<<".";
}

}




I am not programming in C++ very long already so I am sorry if it's a bit of a stupid question...

Is This A Good Question/Topic? 0
  • +

Replies To: letters into numbers problem...

#2 PennyBoki  Icon User is offline

  • system("revolution");
  • member icon

Reputation: 53
  • View blog
  • Posts: 2,334
  • Joined: 11-December 06

Re: letters into numbers problem...

Posted 07 April 2007 - 09:04 AM

Hi if you post the rest of the code maybe I'll be more helpful cuz it may have an error there.
Was This Post Helpful? 0
  • +
  • -

#3 Tuur  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 16-March 07

Re: letters into numbers problem...

Posted 07 April 2007 - 09:12 AM

sorry for posting such a stupid mistake...:(
i see it myself now :S
thx for trying to find out.
srr again for posting such stupid mistake.

for ( i = 0; i <245; i++ )
{
	cout<<numbercode[i];   // <<----- x should be i
	cout<<".";
}


Was This Post Helpful? 0
  • +
  • -

#4 PennyBoki  Icon User is offline

  • system("revolution");
  • member icon

Reputation: 53
  • View blog
  • Posts: 2,334
  • Joined: 11-December 06

Re: letters into numbers problem...

Posted 07 April 2007 - 09:24 AM

Hey no prob I'm glad you've found the solution
and

Quote

sorry for posting such a stupid mistake...sad.gif

Don't beat yourself up, you're obviously a smart person,
HINT: Keep your head up and never give up ;)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1