GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 11-Jan-2004, 07:28
funnyf funnyf is offline
New Member
 
Join Date: Jan 2004
Posts: 2
funnyf is on a distinguished road

coding a word with a givin factor


hi, I have the following problem, I need to code a word with a givin factor
for example:
- word = "ABC"
- factor = 5
'A' + 5, 'B' + 5, 'C' + 5
so the coded word should be "FGH"
can someone help me how I can code this?
this is what i've got, so in the for i 've each letter from the givin word, but how can I count the factor so i it counts 5 letters?
thx a lot..
CPP / C++ / C Code:
#include <iostream.h>

void main()
{
	char woord1[20];
        int factor;
	int teller=-1;

	cout<<"Geef een woord in: ";
	cin>>woord1;
        cout<<"Geef een factor: ";
        cin>>factor;

	while(*(woord1+(++teller))!='\0');

	for(int i=0;i<teller;i++)
	{
		cout<<*(woord1+i)<<" ";
	}
}
  #2  
Old 13-Jan-2004, 04:36
Garth Farley Garth Farley is offline
Invalid Email Address
 
Join Date: May 2002
Location: Ireland
Posts: 638
Garth Farley is a jewel in the roughGarth Farley is a jewel in the roughGarth Farley is a jewel in the rough
This shouldn't be too hard, once you know exactly how chars are stored in the computer's memory. They're stored as 8 bit integers, so (unsigned) up to 256 ACSII characters exist. Each character (including punctuation, and system characters) is assigned a number, the ASCII standard is the main. 'A' is represented by 65, 'B' by 66, and so on (check out www.asciitable.com for the rest)

Say you have
CPP / C++ / C Code:
char letter='a';
To "increase" this letter by 5 places, i.e. to count up 5 letters, you can do the following:
CPP / C++ / C Code:
letter += 5; //or letter = letter +5;
Printing the value of letter will give you 'F'

You just gotta be careful when you reach the end of the alphabet, where does 'Z' go to? Does it wrap around?

GF
  #3  
Old 13-Jan-2004, 08:32
funnyf funnyf is offline
New Member
 
Join Date: Jan 2004
Posts: 2
funnyf is on a distinguished road
thx a lot dude, i've found it.
 
 

Recent GIDBlogDeveloping GUIs with wxPython (Part 3) by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 12:37.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.