stream manipulators

Write your question here.
i need to print to columns of temps,farenheit/celsius....ive got my decimal places lined up and everything centered(im very proud of all that!) i need to showpos and setfill for celsius column only.....


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

void main()
{

cout << "Farenheit" << " " << "Celsius" << endl;
int faren;
float cels;
for (faren = 0; faren <= 212; faren++)
{
cout.setf(ios::showpoint | ios::fixed);
cels = 5 * ((float)faren - 32) / 9;
cout <<setw(5)<< faren << setw(16) <<setprecision(3) << cels << endl;
}

}

appreciate any tips
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>
#include <iomanip>
using namespace std;

int main()
{
    cout << "Farenheit    Celsius\n";
    cout << fixed;
    for (double faren = 0; faren <= 212; faren += 2)
    {
        double cels = 5.0 * (faren - 32.0) / 9.0;
        cout << setprecision(0) << setw(9) << faren << ' '
             << setprecision(3) << setw(10) << cels  << endl;
    }
}

thanx but i also need plus signs for pos cels values and *s instead of spaces in front of cels values....i only know how to showpos and setfill for the whole line, cant figure out how to leave faren alone and change cels
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>
#include <iomanip>

int main()
{
    std::cout << "Farenheit    Celsius\n---------    -------\n"
              << std::fixed << std::setprecision(3) ;
    // for all subsequent output, fixed with three digits after the decimal point

    for( int faren = 0; faren <= 212; faren += 2 ) // note: type of faren is int
    {
        const double cels = 5.0 * ( faren - 32.0 ) / 9.0;

                  // print faren with field width 5, space as fill character, no +sign
        std::cout << std::setw(5) << std::setfill(' ') << std::noshowpos << faren
                  << "       "
                  // print cel with field width 9, '*' as fill character, with +sign
                  << std::setw(9) << std::setfill('*') << std::showpos << cels  << '\n' ;
    }
}
Topic archived. No new replies allowed.