Please help me align this columns!

The program is about recording student's quiz scores with the use of arrays.
Here's the code
 
//code deleted 




The program works fine. But its output is like this:

Q[1]          Q[2]          In.AVERAGE
Bonnie          2          3          2
Bennie          2          3          2
Ov.Ave         2           3          4



I tried different methods like adding and removing some \t's or adding 'Name' for the first column but it really doesn't align.
Please help.

*Edit: sorry. new to cplusplus. I fixed the message so it's readable.
Last edited on
Hi, keskiverto. And thank you for replying to this post! :D

I did the setw, and it still doesn't output the desired results.
Here's what I did:
cout<<" "<<setw(10)<<"\tQ.["<<c + 1<<"]"; worked but still not aligned

and this also didn't.
cout<<"\tQ.["<<c + 1<<"]"<<setw(10);

If I may ask, where should I put it? I know it maybe a simple question but I'm new to c++ please bear with me. D:
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>
#include <iomanip>
using std::setw;
using std::cout;
using std::left;
using std::right;

int main()
{
  const size_t w = 4;
  cout << setw(w+w) << "A" << setw(w) << "B" << '\n';
  cout << left << setw(w) << "foo"
       << right << setw(w) << 7 << setw(w) << 42 << '\n';
  return 0;
}

Thank you very much! It's aligned now. :D
Last edited on
Topic archived. No new replies allowed.