Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8787863
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T22:00:01+00:00 2026-06-13T22:00:01+00:00

code: #include <iostream> #include <iomanip> using namespace std; class Ascii_output { public: void run()

  • 0

code:

#include <iostream>
#include <iomanip>
using namespace std;

class Ascii_output {
public:
    void run() {
        print_ascii();
    }
private:
    void print_ascii() {
        int i, j;                                                           // i is         used to print the first element of each row
                                                                        // j is used to print subsequent columns of a given row
    char ch;                                                            // ch stores the character which is to be printed
    cout << left;

    for (i = 32; i < 64; i++) {                                         // 33 rows are printed out (64-32+1)
        ch = i;
        if (ch != '\n')                                                 // replaces any newline printouts with a blank character
            cout << setw(3) << i << " " << setw(6) << ch;
        else
            cout << setw(3) << i << " " << setw(6);

        for (j = 1; j < 7; j++) {                                       // decides the amount of columns to be printed out, "j < 7" dictates this
            ch += 32*j;                                                 // offsets the column by a multiple of 32
            if (ch != '\n')                                             // replaces any newline printouts with a blank character
                cout << setw(3) << i+(32*j) << " " << setw(6) << ch;
            else
                cout << setw(3) << i+(32*j) << " " << setw(6);
        }

        cout << endl;
    }
    }
};

output:
enter image description here

Why do I not get a properly indented output and weird characters at the values 96 – 255 ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T22:00:02+00:00Added an answer on June 13, 2026 at 10:00 pm

    This line doesn’t do the right thing:

    ch += 32*j;
    

    You want to count by 32, that’s either

    ch += 32;
    

    or

    ch = i + 32*j;
    

    I strongly recommend making the numeric and character values match during your output. So change

    cout << setw(3) << i+(32*j) << " " << setw(6) << ch;
    

    to

    cout << setw(3) << int(ch) << " " << setw(6) << ch;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is my code: #include <iomanip> #include <fstream> #include <iostream> using namespace std; int
The following code #include <iostream> using namespace std; int main() { const char* const
Consider the following code: #include <iostream> using namespace std; int main() { int x,
This very simple code: #include <iostream> using namespace std; void exec(char* option) { cout
Here is my code: #include <iostream> #include <stdlib.h> #include <fstream> using namespace std; int
Given this sample code: #include <iostream> #include <stdexcept> class my_exception_t : std::exception { public:
Consider the following code: #include <iostream> #include <memory> #include <vector> using namespace std; struct
Here is the gpu surf code: #include <iostream> #include <iomanip> #include opencv2/contrib/contrib.hpp #include opencv2/objdetect/objdetect.hpp
In the following code: #include <iostream> template <typename T, size_t N> void cal_size(T (&a)[N])
I have this code: #include <iostream> #include <functional> struct A { int operator()(int i)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.