So I finally I got this to work, but my problem is that it gets very messy when I try to print it as a chart. I have to print the output in a neat tabular format that minimizes the number of lines of output while remaining readable.

When I remove the endl in function displayFahrenheit() and function displayCelsius(), and I also uncomment the if statements, they still do not work appropriately and I am not sure what other way I should try this or if there is a specific way to print charts / matrix format in C++ ? ? ?

My code is the following:

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

#include "Temperatures.h"			

// function fahrenheit returns the Fahrenheit equivalent of a Celsius temperature
double Temperatures::fahrenheit(int countCelsius)
{
 return (((countCelsius * 9.00) / 5.00) + 32);
}

// function celsius returns the Celsius equivalent of a Fahrenheit temperature 
double Temperatures::celsius(int countFahrenheit)
{
 return ((countFahrenheit - 32) * (5.00/9.00));
}

// function displayFahrenheit uses a for loop to call the functions to calculate the Fahrenheit for Celsius 0 to 100 
void Temperatures::displayFahrenheit()
{ 
 cout << "Fahrenheit equivalents for Celsius 0 to 100 degrees are: \n";
 
 for(int counter = 0; counter <= 100; counter++)
 {
  cout << counter <<  setw(5) << "      " << setprecision(2) << showpoint << fixed  << fahrenheit(counter)<< endl;
 
 //if(counter % 10 == 0)
	//cout << endl;
 }
} 

// function displayCelsius uses a for loop to call the functions to calculate the Celsius for Fahrenheit 32 to 212
void Temperatures::displayCelsius()
{
 cout << "\nCelsius equivalents of Fahrenheit 32 to 212 degrees: \n";
 
 for(int counter2 = 32; counter2 <= 212; counter2++)
 {
  cout << counter2 <<  setw(5) << "      " << setprecision(2) << showpoint << fixed  << celsius(counter2) << endl;
 
  //if(counter2 % 18 ==0)
  // cout << endl;
 }
}

Inside the if blocks that you've commented, wait for a character to be pressed by the user. That would print all the results on the console, and at the same time, the user will be able to view them page-wise.

Inside the if blocks that you've commented, wait for a character to be pressed by the user. That would print all the results on the console, and at the same time, the user will be able to view them page-wise.

But I am not suppossed to do that - I need to to print them as a chart, right now I have them going down as a column.

Do you mean a bar chart? Then scale those values by a suitable factor and then display the results. For e.g. for Celsius to Fahrenheit, take 0 to 100 on X-axis, and 32 to 212 on Y-axis. Scale the values so that the chart fits into the console and show the variations. Note: You're expected to display the scale while plotting such bar charts. i.e. 1 '*' = x degree Celsius and so on (where you're using columns of the character '*' as the vertical bars).

Do you mean a bar chart? Then scale those values by a suitable factor and then display the results. For e.g. for Celsius to Fahrenheit, take 0 to 100 on X-axis, and 32 to 212 on Y-axis. Scale the values so that the chart fits into the console and show the variations. Note: You're expected to display the scale while plotting such bar charts. i.e. 1 '*' = x degree Celsius and so on (where you're using columns of the character '*' as the vertical bars).

Nope the problem just states to print charts showing the conversions. - Print the outputs in a neat tabular format that minimizes the number of lines of output while remaining readable.

Nope the problem just states to print charts showing the conversions. - Print the outputs in a neat tabular format that minimizes the number of lines of output while remaining readable.

Sorry, but I'm not able to understand the format of the output you want from the program. I'll be able to help if you describe in a bit detail.

Sorry, but I'm not able to understand the format of the output you want from the program. I'll be able to help if you describe in a bit detail.

Ok – no problem. Well I finally got it to work and below is what I mean. Now I am just trying to get my Celsius to come out correctly because it needs to go from 32 to 212.

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

#include "Temperatures.h"		

// function fahrenheit returns the Fahrenheit equivalent of a Celsius temperature
double Temperatures::fahrenheit(int countCelsius)
{
 return (((countCelsius * 9.00) / 5.00) + 32);
}

// function celsius returns the Celsius equivalent of a Fahrenheit temperature 
double Temperatures::celsius(int countFahrenheit)
{
 return ((countFahrenheit - 32) * (5.00/9.00));
}

void Temperatures::displayFahrenheitHeader()
{
	// display table of Fahrenheit equivalents of Celsius temperatures
   cout << "Fahrenheit equivalents of Celsius temperatures:" << endl;

   // create 4 sets of table headers
   for ( int t=0; t < 4; t++ )
      cout << setw( 8 ) << "Celsius " << setw( 11 ) << " Fahrenheit ";
}

void Temperatures::displayFahrenheitTemperatures()
{
	// display temperatures in blocks of 25
   for ( int i=0; i < 25; i++ )				
   {
      for ( int j=0; j <=75; j +=25 ) 
         cout << setw( 7 ) << i + j << setw( 11 ) << fahrenheit( i + j ) << ' ';

      cout << endl;
   } // end for

   displayFahrenheit_100();
}

void Temperatures::displayFahrenheit_100()
{
	// display equivalent for 100
	cout << setw( 64 ) << 100 << setw( 11 ) << fahrenheit( 100 ) << endl;
}

void Temperatures::displayCelsiusHeader()
{
	// display table of Celsius equivalents of Fahrenheit temperatures
	cout << "Celsius equivalents of  Fahrenheit temperatures:" << endl;	

	// create 4 sets of table headers
	for ( int t=0; t < 4; t++ )
      cout << setw( 7 ) << "Fahrenheit" << setw( 10 ) << "Celsius ";
}

void Temperatures::displayCelsiusTemperatures()
{
	// display temperatures in blocks of 45
	for ( int i=32; i < 57; i++ ) 
	{
      for ( int j=0; j <=75; j +=25 ) 
         cout << setw( 7 ) << i + j 
            << setw( 11 ) << celsius( i + j ) << ' ';

      cout << endl;
	} // end for

	displayCelsius_212();
}

void Temperatures::displayCelsius_212()
{
	// display equivalent for 212
	cout << setw( 64 ) << 212 << setw( 11 ) << celsius( 212 ) << endl;

}

never mind i got it - now I just need to format the decimals.

Basically the celsius loop is:

void Temperatures::displayFahrenheitTemperatures()
{
	// display temperatures in blocks of 25
   for ( int i=0; i < 25; i++ )				
   {
      for ( int j=0; j <=75; j +=25 ) 
         cout << setw( 7 ) << i + j << setw( 11 ) << fahrenheit( i + j ) << ' ';

      cout << endl;
   } // end for

   displayFahrenheit_100();
}
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.