Homework blah

This is a discussion on Homework blah within the C++ Programming forums, part of the General Programming Boards category; Write a program that uses a loop to display the characters for each ASCII code 32 through 127. Display 16 ...

Homework blah

Write a program that uses a loop to display the characters for each ASCII code 32 through 127. Display 16 characters on each line with one space between characters.

We are using the Starting out with C++ Early Objects 6th edition. I really don't know how to start this program, I'm not sure if it wants me to display ever character, or if I have to do get the user to input numbers and give me the characters that it should be or the other way around. If you can please help me that would be great.

"Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
-Christopher Hitchens

You can display your output with the printf function. Use the "%c" formatting string to display your loop counter as a character. #include <stdio.h> to be able to use printf.

Although you could do as Zlatko suggests, I suggest that you practice with more C++ specific I/O instead. You could choose to use a loop counter variable of type char, or of say, type int but cast to char for printing.

I still don't get the postfix and the prefix, if someone could give me a hand that would be great. So help with the chars displaying twice, I don't know how to fix that.
My teacher didn't really explain them...
anyways this is the code

So here's the thing. Prefix or postfix, you're not allowed(*) to do ++ more than once in a statement. So you need to split this up into code that is much easier, by only having one printed char per "cout" statement.

(*)Well, you're allowed, but the compiler is also allowed to do anything it wants -- there's no way to guarantee you'll get the order you desire.