Output Formatting

Hey everyone,

I'm a newbie in C++ and I wanted to know how to format my output in such a way that it looks like this;


Celsius Fahrenheit Celsius Fahrenheit Celsius Fahrenheit Celsius Fahrenheit
0 32 25 77 50 122 75 167
1 33 26 78 51 123 76 168
2 35 27 80 52 125 77 170
3 37 28 82 53 127 78 172
4 39 29 84 54 129 79 174
5 41 30 86 55 131 80 176
6 42 31 87 56 132 81 177
7 44 32 89 57 134 82 179
8 46 33 91 58 136 83 181
9 48 34 93 59 138 84 183
10 50 35 95 60 140 85 185
11 51 36 96 61 141 86 186
12 53 37 98 62 143 87 188
13 55 38 100 63 145 88 190
14 57 39 102 64 147 89 192
15 59 40 104 65 149 90 194
16 60 41 105 66 150 91 195
17 62 42 107 67 152 92 197
18 64 43 109 68 154 93 199
19 66 44 111 69 156 94 201
20 68 45 113 70 158 95 203
21 69 46 114 71 159 96 204
22 71 47 116 72 161 97 206
23 73 48 118 73 163 98 208
24 75 49 120 74 165 99 210
100 212

I think there is a way of formatting using iomanip but not sure how, this is my code so far;



#include <iostream>
using namespace std;

#include <iomanip>
#include <cmath>

int celciustofarenheit (int);
int farenheittocelcius (int);
int celcius;

int main() {
cout << "Celcius" << endl;

while (celcius <=25)
{
cout << setw(7);
cout << celcius << endl;
celcius++;
}

cout << "Celcius" << endl;
while (celcius <=50)
{
cout << setw(10);
cout << celcius << endl;
celcius++;
}
return 0;
}
Last edited on
@ric717

- I know Celsius scale not Celcius

- See this:
http://www.cplusplus.com/reference/iomanip/setw/

- Also see:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <iostream>
#include <iomanip>

using namespace std;

int main(){
    int n = 0;
    cout << "\nEnter an integer: ";
    cin >> n;
    cout << "----------" << '\n';
    cout << "  n   n*n " << '\n';
    cout << "----------" << '\n';
    for( int i = 1; i <= n; ++i)
	cout << setw(3) << i << setw(6) << i * i << '\n';
    return 0;
}
 
Last edited on
Topic archived. No new replies allowed.