Format output to table

The code I have written is suppose to present the data in two columns.

The from temperature has to be right aligned. The left column is to be aligned at the decimal point. The top and bottom lines need to be as long as the sum of both right and left columns. I am unsure if I should set up a for loop for this to work. Any help would be appreciated...

Here is my code:

#include <iostream>
#include <math.h>
#include <iomanip>

using namespace std;

int topChoices; // global variables
double vartemp;

void displayMenu(); // Functions
void getMenuSelection();
void getStartEndAndIncrement();
void CtoF(double lo, double hi, double gap);
void displayCtoFtable(double lo, double hi, double gap);
void FtoC(double lo, double hi, double gap);
void displayFtoCtable(double lo, double hi, double gap);



int main ()
{

double lo(2), hi(2); // local variables
double gap;

do
{
displayMenu();
cin >> topChoices;
cout << endl;

switch (topChoices)
{
case 1: // menu choice for converting Celcius to Farenheit
cout << "Celcius to Farenheit" <<endl;
cout << endl;
cout << "Enter low temperature: " <<endl;
cin >> lo;
cout << "Enter high temperature: " <<endl;
cin >> hi;
cout << "Enter temperature increment: " <<endl;
cin >> gap;
cout << endl;
cout << endl;
cout << " C " << " F " << endl;

do //LOOP
{
CtoF (lo, hi, gap); // converts celcius to farenheit

lo = lo+gap; // adds the user chosen temperatue increment to lo temp

displayCtoFtable(lo, hi, gap); // displays table with conversion values

}

while (lo <= hi); // LOOP END

cout << endl;
break;


case 2: // menu choice for converting Frenheit to Celcius
cout << "Farenheit to Celcius" <<endl;
cout << endl;
cout << "Enter low temperature: " <<endl;
cin >> lo;
cout << "Enter high temperature: " <<endl;
cin >> hi;
cout << "Enter temperature increment: " <<endl;
cin >> gap;
cout << endl;
cout << endl;
cout << " F " << " C " << endl;

do //LOOP
{
FtoC (lo, hi, gap); // converts farenheit to celcius

lo = lo+gap; // adds the user chosen temperatue increment to lo temp

displayFtoCtable(lo, hi, gap); // displays table with conversion values
}

while (lo <= hi); // LOOP END

cout << endl;
break;

case 9: // menu choice for ending program
cout << endl;
break;

default:
cout << "Invalid Input" <<endl;
}



}
while (topChoices != 9);


cin.ignore(1);
return 0;
}

void displayMenu() //Menu Function
{
cout << "Enter -- " <<endl;
cout << "Press 1 to convert from Celcius to Farenheit." <<endl;
cout << "Press 2 to convert from Farenheit to Celcius." <<endl;
cout << "Press 9 to exit." <<endl;
}


void CtoF(double lo,double hi, double gap) //convert celcius to farenheit
{
vartemp = ((9*(lo))/5)+32;

cout << "-------------------------" << endl;
cout << "| " << setw(8) << right <<setprecision(4) << lo << " | " << setw(8)<< setprecision(4) << vartemp << " |" << endl;
}

void displayCtoFtable(double lo,double hi, double gap) // display table with celcius and farenheit values
{
}

void FtoC(double lo,double hi, double gap) //convert farenheit to celcius
{
vartemp = (5*(lo-32))/(9);

cout << "-------------------------" << endl;
cout << "| " << setw(6) << right <<setprecision(4) << lo << " | " << setw(8)<< setprecision(4) << vartemp << " |" << endl;
}

void displayFtoCtable(double lo,double hi, double gap) // display table with farenheit and celcius values
{
}
Topic archived. No new replies allowed.