decrypter

Im creating a void that would read and decrypt some characters in a text file. 10 has been subtracted from the ASCII code, but I feel like im doing this function wrong. EDIT: its supposed to do the first 8 letters, hence the counter.

1
2
3
4
5
6
7
8
  void decrypt(){
	for(int ctr = 0; ctr < 9; ctr++){
		char letter;
		cin.get(letter);
		int x = letter - 10;
		cin >> x;
	}
}
Last edited on
EDIT: its supposed to do the first 8 letters, hence the counter.

How many steps are from 0 to 8? There are nine steps.
ctr = 0
ctr = 1
ctr = 2
ctr = 3
ctr = 4
ctr = 5
ctr = 6
ctr = 7
ctr = 8


... nine steps, even if you never get to ctr = 9 (because 9 is not less than itself).
This means that you read nine letters, instead of eight.

cin >> x;
This means you read (input) a new value into x, discarding the original value.
Yet what you actually want is to print (output) it, do you not?

cout << x;
Topic archived. No new replies allowed.