help with simple formatting?

this is what i have so far but i need help with the formatting,
it should look like this https://elearning.utdallas.edu/bbcswebdav/pid-1687963-dt-content-rid-17094469_1/courses/2178-UTDAL-CS-1336-SEC015-82714/Assign_2.png


I dont have to bold, or include the color, and you can just ignore the arrow next to PCT
this is what i have:
// ConsoleApplication16.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iomanip>
#include <iostream>
using namespace std;

int main()
{
cout << std::setw(20) << std::left << "NFC East team" << " W" << " L" << " T" << " Pct" << " PF" << " PA\n";
cout << std::setw(20) << std::left << "Dallas Cowboys" << 13 << 3 << 0 << 813 << 421 << 306 << '\n';
cout << std::setw(20) << std::left << "New York Giants" << 11 << 5 << 0 << 688 << 310 << 284 << '\n';
cout << std::setw(20) << std::left << "Washington Redskins" << 8 << 7 << 1 << 531 << 396 << 383 << '\n';
cout << std::setw(20) << std::left << "Philadelphia Eagles" << 7 << 9 << 0 << 438 << 367 << 331 << '\n';
return 0;
}

thanks!
That link is inaccessible - it gives me an Error 401 - forbidden.
It asks me to log in with username.password.
Thanks, that link still gives me some problems, it leads to a google search page. But I'm going to move on from that.

It is fairly clear what you're trying to output. I'll cover that first.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <iostream>
#include <iomanip>
#include <string>

using namespace std;

void print_head(string name, string a, string b, string c, string d, string e, string f)
{
    std::cout << std::setw(20) << std::left << name << std::right
              << std::setw(3)  << a 
              << std::setw(3)  << b 
              << std::setw(3)  << c 
              << std::setw(5)  << d 
              << std::setw(5)  << e 
              << std::setw(5)  << f 
              << "\n\n";
}

void print_detail(string name, int a, int b, int c, int d, int e, int f)
{
    std::cout << std::setw(20) << std::left << name << std::right
              << std::setw(3)  << a 
              << std::setw(3)  << b 
              << std::setw(3)  << c 
              << std::setw(5)  << d 
              << std::setw(5)  << e 
              << std::setw(5)  << f 
              << '\n';
}

int main()
{    
    print_head("NFC East team", "W", "L", "T", "Pct", "PF", "PA");
    
    print_detail("Dallas Cowboys", 13, 3, 0, 813, 421, 306);
    print_detail("New York Giants",11, 5, 0, 688, 310, 284);    
    print_detail("Washington Redskins", 8, 7, 1, 531, 396, 383);
    print_detail("Philadelphia Eagles", 7, 9, 0, 438, 367, 331); 
}

NFC East team         W  L  T  Pct   PF   PA

Dallas Cowboys       13  3  0  813  421  306
New York Giants      11  5  0  688  310  284
Washington Redskins   8  7  1  531  396  383
Philadelphia Eagles   7  9  0  438  367  331


But - I'd say your problems start much earlier than that in the program. Where does all that data come from? Is it read in from an input file, or typed at the keyboard by the user, or calculated from some other data? Anyway, whichever of those it is, I think you should be using an array or vector to be storing repetitive data. Then instead of calling the output function many times separately, it could be done just once inside a loop.

Also, I'd suggest that all the data for a single row belongs in some sort of container, such as a class Team. Then you'd have an array of Team objects and so on.

By the way, the two separate functions print_head() and print_detail() could be replaced with a single function by using a template to determine the types of the parameters (e.g. int or string).

1
2
3
4
5
6
7
8
9
10
11
12
template <typename T, typename R>
void print(T name, R a, R b, R c, R d, R e, R f)
{
    std::cout << "  " << std::setw(20) << std::left << name << std::right
              << std::setw(3)  << a 
              << std::setw(3)  << b 
              << std::setw(3)  << c 
              << std::setw(5)  << d 
              << std::setw(5)  << e 
              << std::setw(5)  << f 
              << '\n';
}
Last edited on
Topic archived. No new replies allowed.