rex
9th February 2011, 13:48
Hello friends i have a doubt.. i am working on a Qt based application where i show some temperature data. I have a look up table where i save a temperature value to the db for a decimal value.. Right now i have the decimal value data into a QString which i am comparing with the decimal value and appending the equivalent Temperature value into a QVector which i am saving into the database.
if(str=="387")
{
temperaturedata.append("0");
}else if(str=="414")
{
temperaturedata.append("10");
}else if(str=="441")
{
temperaturedata.append("20");
}else if(str=="469")
{
temperaturedata.append("30");
}else if(str=="497")
{
temperaturedata.append("40");
}else if(str=="525")
{
temperaturedata.append("50");
}
// And for all the other values also
.
.
.
I wanted to know if there was a better way of handling a look up table, i have too many if else statements .. how could i handle this better..
This is how the look up table is.
Temperature Decimal
-40 289
-39 292
-38 294
-37 296
-36 299
-35 301
-34 303
-33 306
-32 308
-31 311
-30 313
-29 315
-28 318
-27 320
-26 323
-25 325
-24 328
-23 330
-22 333
-21 335
-20 337
-19 340
-18 342
-17 345
-16 347
-15 350
-14 352
-13 355
-12 358
-11 360
-10 363
-9 365
-8 368
-7 370
-6 373
-5 375
-4 378
-3 381
-2 383
-1 386
0 388
1 391
2 394
3 396
4 399
5 401
6 404
7 407
8 409
9 412
10 415
11 417
12 420
13 423
14 425
15 428
16 431
17 433
18 436
19 439
20 441
21 444
22 447
23 449
24 452
25 455
26 458
27 460
28 463
29 466
30 469
31 471
32 474
33 477
34 480
35 483
36 485
37 488
38 491
39 494
40 497
41 499
42 502
43 505
44 508
45 511
46 514
47 516
48 519
49 522
50 525
looking for some help.
Thank you
if(str=="387")
{
temperaturedata.append("0");
}else if(str=="414")
{
temperaturedata.append("10");
}else if(str=="441")
{
temperaturedata.append("20");
}else if(str=="469")
{
temperaturedata.append("30");
}else if(str=="497")
{
temperaturedata.append("40");
}else if(str=="525")
{
temperaturedata.append("50");
}
// And for all the other values also
.
.
.
I wanted to know if there was a better way of handling a look up table, i have too many if else statements .. how could i handle this better..
This is how the look up table is.
Temperature Decimal
-40 289
-39 292
-38 294
-37 296
-36 299
-35 301
-34 303
-33 306
-32 308
-31 311
-30 313
-29 315
-28 318
-27 320
-26 323
-25 325
-24 328
-23 330
-22 333
-21 335
-20 337
-19 340
-18 342
-17 345
-16 347
-15 350
-14 352
-13 355
-12 358
-11 360
-10 363
-9 365
-8 368
-7 370
-6 373
-5 375
-4 378
-3 381
-2 383
-1 386
0 388
1 391
2 394
3 396
4 399
5 401
6 404
7 407
8 409
9 412
10 415
11 417
12 420
13 423
14 425
15 428
16 431
17 433
18 436
19 439
20 441
21 444
22 447
23 449
24 452
25 455
26 458
27 460
28 463
29 466
30 469
31 471
32 474
33 477
34 480
35 483
36 485
37 488
38 491
39 494
40 497
41 499
42 502
43 505
44 508
45 511
46 514
47 516
48 519
49 522
50 525
looking for some help.
Thank you