| | |
Homework help needed for displaying ASCII Characters
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Oct 2009
Posts: 17
Reputation:
Solved Threads: 0
Problem: 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.
I have tried solving this problem several ways. I either get blank screen or numbers 1-16. Can anyone lend a hand please?
This is what I got so far
#include <iostream>
using namespace std;
int main()
{
int num = 0;
char letter;
while (num <= 16)
{
letter = 32;
cout << letter << " " << endl;
num++;
}
return 0;
}
tried:
#include <iostream>
using namespace std;
int main()
{
int num = 0;
char letter;
while (num <= 16)
{
letter = 32;
cout << num << " " << endl;
num++;
}
return 0;
}
I have tried solving this problem several ways. I either get blank screen or numbers 1-16. Can anyone lend a hand please?
This is what I got so far
#include <iostream>
using namespace std;
int main()
{
int num = 0;
char letter;
while (num <= 16)
{
letter = 32;
cout << letter << " " << endl;
num++;
}
return 0;
}
tried:
#include <iostream>
using namespace std;
int main()
{
int num = 0;
char letter;
while (num <= 16)
{
letter = 32;
cout << num << " " << endl;
num++;
}
return 0;
}
0
#2 Oct 21st, 2009
Try this:
C++ Syntax (Toggle Plain Text)
char letter = 32; int counter = 0; while (letter < 128) { cout << letter << ' '; counter++; if(counter == 16) { cout << endl; counter = 0; } letter++; }
Last edited by Clinton Portis; Oct 21st, 2009 at 11:43 am.
•
•
Join Date: Oct 2009
Posts: 17
Reputation:
Solved Threads: 0
0
#4 Oct 23rd, 2009
I tried your advice but I am getting a blank output screen. this is what I put in, possible that I am missing something? Please not that I am a beginner and just started to learn this in August of 09. I may not understand what you post so if you could be kind and give an explanation on your code I would greatly appreciate it so I can better understand why it's done like this or that. I would learn more out of it and not just get an answer to my issue.
•
•
Join Date: Jul 2005
Posts: 1,678
Reputation:
Solved Threads: 263
0
#5 Oct 23rd, 2009
Notice the different placements of the curly brackets betweenn the code written by Clinton Portis and your code. He checks the value of counter within the while loop to start a new line if needed, you check it outside the while loop.
Try this: If that prints a char to the screen, then the code posted above this post should work ok, too. If not you could try an explicit cast from int to char like this: though you may want to use the up to date C++ version of casting rather than the older C version I demonstrated above.
Try this:
C++ Syntax (Toggle Plain Text)
#include iostream using namespace std; int main() { char letter = 32; cout << letter; cin.get(); return 0; }
C++ Syntax (Toggle Plain Text)
#include iostream using namespace std; int main() { char letter = (char)32; cout << letter; cin.get(); return 0; }
Klatu Barada Nikto
•
•
Join Date: Oct 2009
Posts: 17
Reputation:
Solved Threads: 0
0
#6 Oct 24th, 2009
Ok I see what I was doing wrong. I followed Portis script and it now displays the characters but it keeps looping, I have to hit Ctrl+C to terminate output screen. I will have to figure out why that happens, thanks for explaining to me why things were done in the syntax, I am a hardware tech and code is a new language for me
![]() |
Similar Threads
- hex->ascii question (Assembly)
- Echo command ASCII characters-batch scripting (Shell Scripting)
- Probably a character set problem, trying to substitute characters (Python)
- send ascii contorl characters (PHP)
- returning number of characters with ASCII code (C)
- Help needed for displaying extended charactors in Tk() (Python)
- Displaying numeric data (Assembly)
- ASCII to BINARY, & VICA VERCA (C++)
Other Threads in the C++ Forum
- Previous Thread: Need help, having input problems.
- Next Thread: Using a CHAR in if statement
| Thread Tools | Search this Thread |
api array based binary bitmap c++ c/c++ calculator char char* class code coding compile console conversion count data database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game getline givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int java lib linkedlist linker list loop looping loops map math matrix memory multiple news node number numbertoword output pointer problem program programming project python random read recursion recursive reference rpg sorting string strings temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






