Help please
Feb 12, 2015 at 11:40pm UTC
So thats the question:
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.
Thats what i wrote so far:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
double C,F,K,R,n,a;
cout <<"Enter starting temperature in Celsius: " ;
cin >> C;
while (C <= -273.15)
{
cout <<"ERROR: Temp must be >= -273.15: " ;
cin >> C;}
{
n = n--;
cout << "Enter increments in degrees Celsius: " ;
cin >> n;
}
{
a= 1; a++;
F= C * 1.8+32;
K= C + 273.15;
R= C * 1.8+32+459.67;
}
{
cout <<" #\t Cels\t Fahr\t Kelv\t Rank" <<endl;
}
cout <<" " << n << setw(4) << " " << C << setw(4) << " " << F
<< setw (6) << " " << K << setw (6) << " " << R << endl;
}
Thats what the instructor looking for:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
Enter starting temperature in Celsius: -500
ERROR: Temp must be >= -273.15: -273.15
Enter increments in degrees Celsius: 100
# Cels Fahr Kelv Rank
1 -273.15 -459.67 0.00 0.00
2 -173.15 -279.67 100.00 180.00
3 -73.15 -99.67 200.00 360.00
4 26.85 80.33 300.00 540.00
5 126.85 260.33 400.00 720.00
6 226.85 440.33 500.00 900.00
7 326.85 620.33 600.00 1080.00
8 426.85 800.33 700.00 1260.00
9 526.85 980.33 800.00 1440.00
10 626.85 1160.33 900.00 1620.00
11 726.85 1340.33 1000.00 1800.00
12 826.85 1520.33 1100.00 1980.00
13 926.85 1700.33 1200.00 2160.00
14 1026.85 1880.33 1300.00 2340.00
15 1126.85 2060.33 1400.00 2520.00
16 1226.85 2240.33 1500.00 2700.00
17 1326.85 2420.33 1600.00 2880.00
18 1426.85 2600.33 1700.00 3060.00
19 1526.85 2780.33 1800.00 3240.00
20 1626.85 2960.33 1900.00 3420.00
Press any key to continue . . .
My question is to know how to make the sequence from 1 to 20 and whats the best statment for increment
Thanks
Feb 13, 2015 at 7:41am UTC
for
loop:
1 2 3 4 5
for (int i - 1; i <= 20; ++i)
{
std::cout << i << '\t' << Cels /*...*/ ;
Cels += increment;
}
Feb 13, 2015 at 6:19pm UTC
Thanks man
Topic archived. No new replies allowed.