Problem with a simple beginner program...

Hi,

I tried to build a simple program giving temperatures in °C and °F. Here is the code:

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
35
36
37
38
 #include <iostream>
#include <cstring>

using namespace std;

int main(){
double Tm=0; //minimum Temp
double TM=50000; //Max Temp
double T0,T1,Ts; //given minimum, max and step Temps

cout<<"Please give in a lower limit >="<<Tm<<"°C:";
cin>>T0; //minimum Temp
cout<<"'\n'Please give in a higher limit <="<<TM<<"°C:";
cin>>T1; //Max Temp
cout<<"'\n'Please give in a step, 0 < step < "<<T1-T0<<":";
cin>>Ts; //step

int nbrlines;
double nbrline;
nbrline = 1+(T1-T0)/Ts;
nbrlines=(int)nbrline;  //number of lines in the array to use later
double array[2][nbrlines];

for(int x=0;x<nbrlines;x++){
    array[x][0]=T0+x*Ts;
    array[x][1]=32+9*(array[x][0])/5;} //build the array

//printing:

cout<<"Conversion table:\n";
cout<<"Celsius"<<'\t'<<"Fahrenheit\n";
cout<<"-------"<<'\t'<<"----------\n";
for(int x=0;x<nbrlines;x++){
    cout<<array[x][0]<<'\t'<<array[x][1]<<'\n';
    }
    cin.get();
}


The problem is that,for temperatures between 10 and 20°C separted by 1°C for instance, the result is correct until T=15°C, the next line is "nan 5.56112e+260" (all the following are false too.

(for a step of °C, I always have "20 68)

Thank you !
Topic archived. No new replies allowed.