setw issue, how to go about it?

I am trying to set the width of the data values which the user will input when using the program but I don't know how to get it to show the values when I tryto set the width of the variables in a nice column please help me in telling me what I am doing wrong, I know its probably something simple like a ; or so any help will be appreciated!

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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
//Programming Assignment 4

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

int main()
{

double q1r1, q2r1, q3r1, q4r1;
double q1r2, q2r2, q3r2, q4r2;
double q1r3, q2r3, q3r3, q4r3;

double r1totalsales;
double r2totalsales;
double r3totalsales;

double q1totalsales;
double q2totalsales;
double q3totalsales;

char Q1 [3];
char Q2 [3];
char Q3 [3];
char Q4 [3];
char Total [6];

cout << "Welcome to the Jasmine McFadden sales report calculator! " <<"\n";

string device_name;
	cout << "Enter the devie name (Camera or Robot)";
	cin >> device_name;

cout << "Enter sales by quarter for region 1: ";
cin >> q1r1 >> q2r1 >> q3r1 >> q4r1;

cout << "Enter sales by quarter for region 2: ";
cin >> q1r2 >> q2r2 >> q3r2 >> q4r2;

cout << "Enter sales amounts for region 3: ";
cin >> q1r3 >> q2r3 >> q3r3 >> q4r3;

r1totalsales = q1r1 + q2r1 + q3r1 + q4r1;
r2totalsales = q1r2 + q2r2 + q3r2 + q4r2;
r3totalsales = q1r3 + q2r3 + q3r3 + q4r3;

q1totalsales = q1r1 + q1r2 + q1r3;
q2totalsales = q2r1 + q2r2 + q2r3;
q3totalsales = q3r1 + q3r2 + q3r3;

cout << "CSCI Sales Report - Device: " << device_name; 
cout << "--------------";

std::cout << std::setw(20);
	std::cout << Q1 << std::endl;
std::cout << std::setw(10);
	std::cout << Q2 << std::endl;
std::cout << std::setw(10);
	std::cout << Q3 << std::endl;
std::cout << std::setw(10);
	std::cout << Q4 << std::endl;
std::cout << std::setw(10);
  std::cout << Total << std::endl;

system ("pause");
	return 0;
}
Last edited on
1
2
3
4
5
6
7
8
#include <iostream>
#include <iomanip>

int main()
{
        using namespace std;
        cout << setw(10) << 1 << endl;
}
I think you are using setw properly, but you are printing garbage. Q1, Q2, Q3, Q4 and Total are char arrays that have not been initialized. You are printing out garbage.
Topic archived. No new replies allowed.