Temp Converter

write a program that creates and displays a table of temperature conversions. Get the starting temperature from the keyboard in degrees Celsius (do not allow input of a value below absolute zero). Also get an integer value to represent the number of degrees to increment for each of a 20 row table (do not allow the increment value to be less than one. The first column will be a row number starting with one, follow by the Celsius value and then the conversions into Fahrenheit, Kelvin, and Rankine. Be sure that all columns are neatly right aligned for a variety of inputs.
Modularize the temperature conversion program in Lab 04. Use the breakdown of modules from item 4 (above) as the minimum level of modularity. Be sure that you comment each function correctly.


NEED HELP
This is not a homework site. We won't do your homework for you. However we are always willing to help solve problems you encountered, correct mistakes you made in your code and answer your questions.

We didn't see your attempts to solve this problem yourself and so we cannot correct mistakes you didn't made and answer questions you didn't ask. To get help you should do something yourself and get real problems with something. If your problem is "I don't understand a thing", then you should go back to basics and study again. As it is impossible to find derivative of function without knowledge in arithmetic, you cannot do more complex tasks in programming without clear understanding of basics
// Temperature Converter
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
int main ()
{
double x, num, Cels, Fahr, Kelv, Rank;
cout << "Enter a temperature in Celsius: ";
cin >> Cels;
if (Cels < -273.15)
{
cout << "Temperature must be greater than or equal to -273.15: ";
cin >> Cels;
}
{
cout << "Enter the increment in Celsius: ";
cin >> num;
}
if (num < 1)
{
cout << "Increment must not be less than one: ";
cin >> num;
}
{
x = 0; x++;
Fahr = (Cels * 1.8) +32;
Kelv = Cels + 273.15;
Rank = (Cels + 273.15) * 1.8;
}

{
cout << "#\tCels\t\tFahr\t\tKelv\t\tRank" << endl;
}
for ( x - 1; x<=20; ++x)
{
cout << x << '\t' << Cels << '\t' << '\t'
<< Fahr << '\t' << '\t' << Kelv << '\t' << '\t' << Rank;
Cels += num;
Fahr = (Cels * 1.8) + 32;
Kelv = Cels + 273.15;
Rank = (Cels + 273.15) * 1.8;
cout << endl;
}
}

this is what i have but im not sure how to modulize it
but im not sure how to modulize it


You have to break it down into functions.
For example,
A function that converts celcius to fahrenreit.
A function that converts celcius to kelvin.
A function that takes the user input
More functions...

The output could look something like this...
What is temperature degree in Celcius: -273.16
Your input -273.16 is incorrect.
Please, try again.
What is temperature degree in Celcius: 20
Input the number of degrees to increment up to 20 rows: 0
Your input 0 is incorrect.
Please, try again.
Input the number of degrees to increment up to 20 rows: 5

 #      Celcius    Fahrenheit     Kelvin         Rankine
----------------------------------------------------------------------------
 1        20           68         293.15         527.67
 2        25           77         298.15         536.67
 3        30           86         303.15         545.67
 4        35           95         308.15         554.67
 5        40          104         313.15         563.67
 6        45          113         318.15         572.67
 7        50          122         323.15         581.67
 8        55          131         328.15         590.67
 9        60          140         333.15         599.67
10        65          149         338.15         608.67
11        70          158         343.15         617.67
12        75          167         348.15         626.67
13        80          176         353.15         635.67
14        85          185         358.15         644.67
15        90          194         363.15         653.67
16        95          203         368.15         662.67
17       100          212         373.15         671.67
18       105          221         378.15         680.67
19       110          230         383.15         689.67
20       115          239         388.15         698.67


https://www.youtube.com/watch?v=xp_D1kt3lxs&feature=youtu.be
https://www.youtube.com/watch?v=gpzFBuINFZk&feature=youtu.be
Last edited on
how would i do that
Take a look at the functions link:
http://www.cplusplus.com/doc/tutorial/functions/
// Temperature Converter
#include <iostream>
#include <cmath>
using namespace std;
int getInput ();

void getInput (double& Cels, double& num)
{
cout << "Enter a temperature in Celcius: ";
cin >> Cels;
if (Cels < -273.15)
{
cout << "Temperature must be greater than or equal to -273.15: ";
cin >> Cels;
}
cout << "Enter the increment in Celsius: ";
cin >> num;

if (num < 1)
{
cout << "Increment must not be less than one: ";
cin >> num;
}
}
This is what i have so far, how would i now separate into converting into all the different columns
// Temperature Converter
#include <iostream>
#include <cmath>
using namespace std;

#define COLUMN_SEPARATOR "\t|"

void getInput (double& Cels, double& num)
{
cout << "Enter a temperature in Celcius: ";
cin >> Cels;
if (Cels < -273.15)
{
cout << "Temperature must be greater than or equal to -273.15: ";
cin >> Cels;
}
cout << "Enter the increment in Celsius: ";
cin >> num;

if (num < 1)
{
cout << "Increment must not be less than one: ";
cin >> num;
}
}
double toFahrenheit(double Cels)
{
return Cels*(9/5) + 32;
}
double toKelvin (double Cels)
{
return (Cels + 273.15);
}
double toRankine (double Cels)
{
return (Cels + 273.15) * 1.8;
}
void printTable (double x, double num)
{
cout << "Celsius" << COLUMN_SEPARATOR << "Fahrenheit" << COLUMN_SEPARATOR << "Kelvin" << COLUMN_SEPARATOR << "Rankine" << endl;
for (double x = 1; x<=20; ++x)
{
cout << x << COLUMN_SEPARATOR << toFahrenheit << COLUMN_SEPARATOR << toKelvin << COLUMN_SEPARATOR << toRankine <<endl;
}
}
int main ()
{
double x, num;
getInput (x, num);
printTable (x, num);
return 0;
}

This is what i got, but my output is definitely not what i want.
cout << x << COLUMN_SEPARATOR << toFahrenheit << COLUMN_SEPARATOR << toKelvin << COLUMN_SEPARATOR << toRankine << endl;

That "garbage" value that you see is the memory address of the functions that you are calling.

You should call the functions like...
cout << x << COLUMN_SEPARATOR << toFahrenheit(x) << COLUMN_SEPARATOR << toKelvin(x) << COLUMN_SEPARATOR << toRankine(x) << endl;

Have you read about the manipulator setw(int)?
http://www.cplusplus.com/reference/iomanip/setw/
Topic archived. No new replies allowed.