I am currently going through a c++ book trying to do the problems at the end of the chapters. They dont provide solutions so im kind of stuck. My problem is:
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.
Currently it prints out the ASCII characters fine but it looks like a mess. i dont know how to get it to do 16 characters on each line.
Here is The code i have with Sample output.
#include <iostream>
using namespace std;
int main()
{
for (int i = 0; i <= 127; ++i)
{
cout << char(i) << " ";
for (int j = 1; j <= 16; j++)
{
// cout << endl;
}
}
//cout << endl;
return 0;
}
sample output: (the white space is included in the output. i did a straight copy and paste.
1 2 3 4 5 6 7 8 9 : ; < = > ? @ A B C D E F G H I J K L M N O P Q R S T U V W X Y Z [ \ ] ^ _ ` a b c d e f g h i j k l m n o p q r s t u v w x y z { | } ~ Press [Enter] to close the terminal ...