Loop

Mar 31, 2016 at 3:20am
The character 'b' is char('a'+1), 'c' is char('a'+2), etc. Use a loop to write out a table of characters with their corresponding integer values.
a 97
b 98
...........

After reading about loops in "Programming Principles" by Bjarne I don't know how to even begin this. How do you distinguish between the initialization of character 'a' and its decimal value 97? Please provide an explanation on how to create code that iterates this.
Mar 31, 2016 at 3:35am
If you are just starting out with C++, I wouldn't read anything from Bjarne just yet. He typically writes about very advanced topics. Start simple:

1) Make sure you can loop from a - z
2) Then see if you can convert (or cast) the letter to its ASCII value. You could do something like this:
1
2
char a = 'A';
cout << (int)a;


I'm pretty sure that works. It would output a 65.
Topic archived. No new replies allowed.