I hate being a perfectionist it's driving me crazy.

I can get it to resize to the words, but when I replace them with small 3 letter words, the design messes up and everything gets out of place.

I'm a beginner and you guys are probably going to laugh at my code because I know I am making this harder than it should be, and most likely doing it completely wrong.

My main goal is to have it where I can re-use the code and only have to replace the title for each column, and it automatically make me a nice table that lines up perfect.

Here is what I have so far.

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

double celcius(double);

int main ()
{
    double F=0, C;

    cout << "|-" << setfill('*') << setw(24) << "-|" <<endl;
    cout << setfill(' ') << setw(12) << left << "|Fahrenheit|" <<  setfill(' ');
    cout << setw(14) << right << "|Celsius |" <<  endl;
    cout << "|-" <<  setfill('*') << setw(24) << "-|" << endl;

    for (int i=0; i<=20; i++)
    {
        C = celcius(F);
        cout.precision(1);
        cout <<"|" <<  setfill(' ') << setw(7) << fixed << F <<"  { | }";
        cout << setw(7) << right << C << "   |" << endl;
            F++;
    }
    cout << "'-" << setfill('-') << setw(24) << "-'" << endl;
}
    double celcius(double F)
    {
        double temp;
        temp = ((5.0/9.0)*(F-32));
        return temp;
    }

Design

|-**********************-|
|Fahrenheit|    |Celsius |
|-**********************-|
|    0.0  { | }  -17.8   |
|    1.0  { | }  -17.2   |
|    2.0  { | }  -16.7   |
|    3.0  { | }  -16.1   |
|    4.0  { | }  -15.6   |
|    5.0  { | }  -15.0   |
|    6.0  { | }  -14.4   |
|    7.0  { | }  -13.9   |
|    8.0  { | }  -13.3   |
|    9.0  { | }  -12.8   |
|   10.0  { | }  -12.2   |
|   11.0  { | }  -11.7   |
|   12.0  { | }  -11.1   |
|   13.0  { | }  -10.6   |
|   14.0  { | }  -10.0   |
|   15.0  { | }   -9.4   |
|   16.0  { | }   -8.9   |
|   17.0  { | }   -8.3   |
|   18.0  { | }   -7.8   |
|   19.0  { | }   -7.2   |
|   20.0  { | }   -6.7   |
'------------------------'

I'm a beginner programmer and have been going at this whole thing for hours. I know you pros know some fancy tricks to get all this done a lot easier. If someone could help me it would be GREATLY appreciated! I Thanks and look forward to seeing what you guys come up with.

deleted old code

Finished Design
If anyone wants to use the design just replace Name1 and Name2 with what ever you want in the code.

|-**********************-|
| Name1|          |Name2 |
|-**********************-|
|    0.0  { | }  -17.8   |
|    1.0  { | }  -17.2   |
|    2.0  { | }  -16.7   |
|    3.0  { | }  -16.1   |
|    4.0  { | }  -15.6   |
|    5.0  { | }  -15.0   |
|    6.0  { | }  -14.4   |
|    7.0  { | }  -13.9   |
|    8.0  { | }  -13.3   |
|    9.0  { | }  -12.8   |
|   10.0  { | }  -12.2   |
|   11.0  { | }  -11.7   |
|   12.0  { | }  -11.1   |
|   13.0  { | }  -10.6   |
|   14.0  { | }  -10.0   |
|   15.0  { | }   -9.4   |
|   16.0  { | }   -8.9   |
|   17.0  { | }   -8.3   |
|   18.0  { | }   -7.8   |
|   19.0  { | }   -7.2   |
|   20.0  { | }   -6.7   |
'------------------------'

You're conversion from Fahrenheit to Celsius isn't correct. Try:

double celsius(double F)
{
    return F*9.0/5.0 + 32;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.