Answer to Question #166625 in C++ for Earl Davis Jr.

Question #166625

We have talked a bit about how chars are really just ASCII integers. Let's see this in action. We will show the characters starting at ASCII 33 and end with a user-supplied number. Use a for loop to output the characters with two spaces between each.

 

Prompt:

This program will output the ASCII characters starting at 33

Enter the integer for the last ASCII character you wish to see:  [user types: 43]

 

Output:

! " # $ % & ' ( ) * +  

 

Notes and Hints:

1) You MUST use a FOR LOOP

2) Hint: Which operator from Chp 3 allows us to convert from one data type to another?

3) FYI only: http://www.asciitable.com/


1
Expert's answer
2021-02-26T05:36:53-0500
//Solution-1

using namespace std;


main(void)
{
	int StartChar = 33,EndChar,n;
	cout<<"\nEnter the last character ASCII (decimal): "; cin>>EndChar;
	
	cout<<"\n\nCharacters from ASCII = "<<StartChar<<" to ASCII = "<<EndChar<<endl;
	for(n=int(StartChar);n<=int(EndChar);n++)
	{
		cout<<char(n)<<" ";
	}
	return(0);
}




Solution-2

cout<<char(n)<<" ";
The above statement converts ASCII code to character and displays the equivalent character.


Answer to this question

Send



Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment