News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

Wind Chill Program C++

Started by herge, February 22, 2013, 02:24:07 AM

Previous topic - Next topic

herge

 Hi Rubber Duck Fans:

Are we ready for some real chilly and cold math.
The government of USA (NOAA) supplied the formula
and the rest is just c++ it was original a Borland C program
but now works on c++ 2008 with a few additions.

// windchill.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
/* WIND.CPP 11/20/2003 10:30
   Author: herge
   Location: Waterloo, Ontario, CANADA
   WWW.nws.NOAA.gov
   Wind Chill = 35.74 + 0.6215 * T - 35.75(V**0.16) +
   0.4275 * T(V**0.16)
   Where T = Degrees F and V = mph */
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <conio.h>
  using std::cout;
  using std::endl;
  using std::setw;
  using std::endl;

int _tmain(int argc, _TCHAR* argv[])
    {
    int i = 0; /* t index(f)*/
    int j = 0; /* v index(m)*/
    const int k = 248; /* Degree Symbol */
    int w = 0; /* Temperature Degrees F */
    double v6 = 0; /* Miles ** 0.16*/
    double c = 40; /* initial t(F) */
    int d = 5; /* initial v (mph) */
    double f = 1;
    cout << "MPH\tWind Chill Factor (Temperature +40" << char(k)
<<"F to -40" << char(k) << "F" << endl;
    cout << " V  ";
    for ( i = 0 ; i < 17; i ++)
    cout << setw(3) << ( 40 - ( i * 5 )) << " " ;
    cout << char(k) << "F" << endl;
    for ( i = 1; i < 13; i++ )
        { /* Velocity */
        d = i * 5.0 * f;
        cout << setw(3) << d << " ";
        /* MPH to power of (0.16) */
        /* for wind chill formula */
        /* calculate in outer loop*/
        v6 = pow(d, 0.16);
        for ( j = 0; j < 17; j++)
            { /* Temperature */
            c = 40 - (j * 5);
            w = 35.74 + 0.6215 * c - 35.75 * v6 +
            0.4275 * c * v6;
            cout << setw(3) << w << " ";
            if( j == 16) cout << char(k) << "F";
        }
        cout << endl;
    }
    cout << "MPH" << endl;
    getch();
return 0;
}

  Expected output

MPH     Wind Chill Factor (Temperature +40°F to -40°F
V   40  35  30  25  20  15  10   5   0  -5 -10 -15 -20 -25 -30 -35 -40 °F
  5  36  30  24  18  12   7   1  -4 -10 -16 -22 -28 -34 -39 -45 -51 -57 °F
10  33  27  21  15   8   2  -3  -9 -15 -22 -28 -34 -40 -46 -53 -59 -65 °F
15  31  25  19  12   6   0  -6 -12 -19 -25 -32 -38 -45 -51 -57 -64 -70 °F
20  30  23  17  10   4  -2  -8 -15 -21 -28 -35 -41 -48 -54 -61 -67 -74 °F
25  29  22  16   9   2  -4 -10 -17 -24 -30 -37 -44 -50 -57 -64 -70 -77 °F
30  28  21  14   8   1  -5 -12 -19 -25 -32 -39 -46 -53 -59 -66 -73 -80 °F
35  27  20  13   7   0  -6 -13 -20 -27 -34 -41 -48 -54 -61 -68 -75 -82 °F
40  26  19  13   6   0  -7 -14 -21 -28 -35 -42 -49 -56 -63 -70 -77 -84 °F
45  26  19  12   5  -1  -8 -15 -22 -29 -37 -44 -51 -58 -65 -72 -79 -86 °F
50  25  18  11   4  -2  -9 -16 -24 -31 -38 -45 -52 -59 -66 -73 -80 -87 °F
55  25  18  10   3  -3 -10 -17 -24 -32 -39 -46 -53 -60 -67 -75 -82 -89 °F
60  24  17  10   3  -4 -11 -18 -25 -33 -40 -47 -54 -61 -69 -76 -83 -90 °F
MPH



Do NOT try to change the range of temperatures or wind speed
It will not work!
Getting the degee symbol to print was a real pain.

Regards herge
Regards herge
Read "Slow Death by Rubber Duck"
for chemical Laughs.

hfheatherfox07

@ herge , you seem to know C++
Can you get the about box and menus to work in this tutorial?

http://masm32.com/board/index.php?action=dlattach;topic=1402.0;attach=1250

I just got mad and did it in masm :)

Can you fix it?
Your code and your skills will be assimilated. Your programming language is irrelevant.
We are the ASM Borg and you will become part of us. Compile and be assembled.

hfheatherfox07

I tried compiling this but I get errors  :(

Your code and your skills will be assimilated. Your programming language is irrelevant.
We are the ASM Borg and you will become part of us. Compile and be assembled.

herge


Hi hfheatherfox07:

You will get three warning messages but it should go.

1>Compiling...
1>stdafx.cpp
1>Compiling...
1>windchill.cpp
1>c:\documents and settings\owner\my documents\visual studio 2008\projects\windchill\windchill\windchill.cpp(39) : warning C4244: '=' : conversion from 'double' to 'int', possible loss of data
1>c:\documents and settings\owner\my documents\visual studio 2008\projects\windchill\windchill\windchill.cpp(49) : warning C4244: '=' : conversion from 'double' to 'int', possible loss of data
1>c:\documents and settings\owner\my documents\visual studio 2008\projects\windchill\windchill\windchill.cpp(56) : warning C4996: 'getch': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _getch. See online help for details.
1>        c:\program files\microsoft visual studio 9.0\vc\include\conio.h(145) : see declaration of 'getch'
1>Compiling manifest to resources...
1>Microsoft (R) Windows (R) Resource Compiler Version 6.1.6723.1
1>Copyright (C) Microsoft Corporation.  All rights reserved.
1>Linking...
1>LINK : C:\Documents and Settings\Owner\My Documents\Visual Studio 2008\Projects\windchill\Debug\windchill.exe not found or not built by the last incremental link; performing full link
1>Embedding manifest...
1>Microsoft (R) Windows (R) Resource Compiler Version 6.1.6723.1
1>Copyright (C) Microsoft Corporation.  All rights reserved.
1>Build log was saved at "file://c:\Documents and Settings\Owner\My Documents\Visual Studio 2008\Projects\windchill\windchill\Debug\BuildLog.htm"
1>windchill - 0 error(s), 3 warning(s)
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========



Regards herge

Regards herge
Read "Slow Death by Rubber Duck"
for chemical Laughs.

herge


Hi heather:

you called stdafx twice?

Regards herge
Regards herge
Read "Slow Death by Rubber Duck"
for chemical Laughs.

hfheatherfox07

I am sorry I copied your source as you posted it, not compiling
Maybe you have different  stdafx.h ?
Why are you compiling stdafx.cpp ?



I have no idea what your answer was? :(
Your code and your skills will be assimilated. Your programming language is irrelevant.
We are the ASM Borg and you will become part of us. Compile and be assembled.

hfheatherfox07

Quote from: herge on February 22, 2013, 05:05:46 AM

Hi heather:

you called stdafx twice?

Regards herge


What are you talking about?
Sorry new to C++

EDIT:
Please take a look at the batch file that I use to complie !
I'm am not using visual studio 2008

Can you include all your includes?
Your code and your skills will be assimilated. Your programming language is irrelevant.
We are the ASM Borg and you will become part of us. Compile and be assembled.

herge


hi heather:


C:\down\temp>dir
Volume in drive C has no label.
Volume Serial Number is E491-9F6C

Directory of C:\down\temp

02/21/2013  12:52 PM    <DIR>          .
02/21/2013  12:52 PM    <DIR>          ..
02/21/2013  12:50 PM    <DIR>          main 5-Resources Icons, Dialogs and Menu

02/21/2013  01:21 PM    <DIR>          Wind Chill Program C++
               0 File(s)              0 bytes
               4 Dir(s)  111,687,221,248 bytes free

C:\down\temp>cd ,\wind chill program c++
The system cannot find the path specified.

C:\down\temp>cd .\wind chill program c++

C:\down\temp\Wind Chill Program C++>dir
Volume in drive C has no label.
Volume Serial Number is E491-9F6C

Directory of C:\down\temp\Wind Chill Program C++

02/21/2013  01:21 PM    <DIR>          .
02/21/2013  01:21 PM    <DIR>          ..
02/21/2013  01:21 PM               551 Build it.bat
02/21/2013  12:59 PM               552 buildit.bat
02/21/2013  12:52 PM               551 buildit.txt
02/21/2013  12:58 PM               552 builit.bar.txt
02/21/2013  01:21 PM             1,059 StdAfx.h
02/21/2013  01:21 PM             1,729 windchill.cpp
               6 File(s)          4,994 bytes
               2 Dir(s)  111,687,221,248 bytes free

C:\down\temp\Wind Chill Program C++>build it
'build' is not recognized as an internal or external command,
operable program or batch file.

C:\down\temp\Wind Chill Program C++>"build it"
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 15.00.30729.01 for 80x86
Copyright (C) Microsoft Corporation.  All rights reserved.

cl : Command line warning D9002 : ignoring unknown option '/ML'
windchill.cpp
windchill.cpp(31) : warning C4310: cast truncates constant value
windchill.cpp(32) : warning C4310: cast truncates constant value
windchill.cpp(36) : warning C4310: cast truncates constant value
windchill.cpp(39) : warning C4244: '=' : conversion from 'double' to 'int', pos
ible loss of data
windchill.cpp(49) : warning C4244: '=' : conversion from 'double' to 'int', pos
ible loss of data
windchill.cpp(51) : warning C4310: cast truncates constant value
windchill.cpp(56) : warning C4996: 'getch': The POSIX name for this item is dep
ecated. Instead, use the ISO C++ conformant name: _getch. See online help for d
tails.
        C:\Program Files\Microsoft Visual Studio 9.0\VC\INCLUDE\conio.h(145) :
ee declaration of 'getch'
windchill.cpp(21) : warning C4100: 'argv' : unreferenced formal parameter
windchill.cpp(21) : warning C4100: 'argc' : unreferenced formal parameter
Press any key to continue . . .
Microsoft (R) Incremental Linker Version 5.12.8078
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.

Press any key to continue . . .
C:\down\temp\Wind Chill Program C++>dir
Volume in drive C has no label.
Volume Serial Number is E491-9F6C

Directory of C:\down\temp\Wind Chill Program C++

02/21/2013  01:27 PM    <DIR>          .
02/21/2013  01:27 PM    <DIR>          ..
02/21/2013  01:21 PM               551 Build it.bat
02/21/2013  12:59 PM               552 buildit.bat
02/21/2013  12:52 PM               551 buildit.txt
02/21/2013  12:58 PM               552 builit.bar.txt
02/21/2013  01:21 PM             1,059 StdAfx.h
02/21/2013  01:21 PM             1,729 windchill.cpp
02/21/2013  01:27 PM           162,816 windchill.exe
               7 File(s)        167,810 bytes
               2 Dir(s)  111,687,024,640 bytes free

C:\down\temp\Wind Chill Program C++>windchill
MPH     Wind Chill Factor (Temperature +40°F to -40°F
V   40  35  30  25  20  15  10   5   0  -5 -10 -15 -20 -25 -30 -35 -40 °F
  5  36  30  24  18  12   7   1  -4 -10 -16 -22 -28 -34 -39 -45 -51 -57 °F
10  33  27  21  15   8   2  -3  -9 -15 -22 -28 -34 -40 -46 -53 -59 -65 °F
15  31  25  19  12   6   0  -6 -12 -19 -25 -32 -38 -45 -51 -57 -64 -70 °F
20  30  23  17  10   4  -2  -8 -15 -21 -28 -35 -41 -48 -54 -61 -67 -74 °F
25  29  22  16   9   2  -4 -10 -17 -24 -30 -37 -44 -50 -57 -64 -70 -77 °F
30  28  21  14   8   1  -5 -12 -19 -25 -32 -39 -46 -53 -59 -66 -73 -80 °F
35  27  20  13   7   0  -6 -13 -20 -27 -34 -41 -48 -54 -61 -68 -75 -82 °F
40  26  19  13   6   0  -7 -14 -21 -28 -35 -42 -49 -56 -63 -70 -77 -84 °F
45  26  19  12   5  -1  -8 -15 -22 -29 -37 -44 -51 -58 -65 -72 -79 -86 °F
50  25  18  11   4  -2  -9 -16 -24 -31 -38 -45 -52 -59 -66 -73 -80 -87 °F
55  25  18  10   3  -3 -10 -17 -24 -32 -39 -46 -53 -60 -67 -75 -82 -89 °F
60  24  17  10   3  -4 -11 -18 -25 -33 -40 -47 -54 -61 -69 -76 -83 -90 °F
MPH

C:\down\temp\Wind Chill Program C++>

/code]

It works.

Do not put spaces in filnames because you
have to quote them i e
>"build it"

If you want Dos start vc and use tools command prompt
the tools is above vc click it and then click command prompt.

Regards herge
Regards herge
Read "Slow Death by Rubber Duck"
for chemical Laughs.

hfheatherfox07

I double click the batch file , that is all and it will NOT compile :(
And as for that other attachment I can not add about dialog , or menu to code
Dunno how with out error :(


Not opening any DOS command prompt ??
I have Microsoft SDK and Microsoft Visual C++ Toolkit 2003

not same includes as you !!!!
That is why I asked for them


I will stick to masm32
As long as you instal in C drive , a persons can download your asm source with a batch file and build an app, simple!

So much hassle with C and C ++
H
I have no idea what your answer was, I double click that batch file and it still won't compile ?
It's OK.........

Your code and your skills will be assimilated. Your programming language is irrelevant.
We are the ASM Borg and you will become part of us. Compile and be assembled.

herge

#9
 Hi DednDave:

If you got Microsoft vc 2008 or vc 2005 in Arixona down south try the
wind chill program  please,

Hi heather:

Dos does not like spaces in Filenames get use to it or
as I have said before quote it. i e
>"build it"
or to put iy another way dos stops at the space so it thinks it
is the second arguement when it is NOT.
If you DO NOT QUOTE it can not find the next arguement and
because if found the Space it think its got the arguement when
it only has half of it!

This is vc 2008 and it has different DLLs running
and is very difficult to run with out them.

I think you should try Borland 5.5 compiler and make sure you
get the .cfg files thal are short files. It's about 8 meg.
I can assure you will need the cfg files for Borland to go.

C:\borland\bcc55\bin>dir *.cfg
Volume in drive C has no label.
Volume Serial Number is E491-9F6C

Directory of C:\borland\bcc55\bin

07/15/2008  05:34 AM                60 bcc32.cfg
07/15/2008  05:45 AM                28 ilink.cfg
07/15/2008  05:57 AM                28 ilink32.cfg
               3 File(s)            116 bytes
               0 Dir(s)  111,672,188,928 bytes free



You won't actual find these files you have to create them
manually. But you will find imfomation at the down load site
as to what is in them.

Regards herge
Regards herge
Read "Slow Death by Rubber Duck"
for chemical Laughs.

hfheatherfox07

This are my errors

Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 13.10.3077 for 80x86
Copyright (C) Microsoft Corporation 1984-2002. All rights reserved.

windchill.cpp
windchill.cpp(31) : warning C4310: cast truncates constant value
windchill.cpp(32) : warning C4310: cast truncates constant value
windchill.cpp(36) : warning C4310: cast truncates constant value
windchill.cpp(39) : warning C4244: '=' : conversion from 'double' to 'int', poss
ible loss of data
windchill.cpp(44) : error C2666: 'pow' : 7 overloads have similar conversions
        C:\Program Files\Microsoft Visual C++ Toolkit 2003\include\math.h(620):
could be 'long double pow(long double,int)'
        C:\Program Files\Microsoft Visual C++ Toolkit 2003\include\math.h(618):
or       'long double pow(long double,long double)'
        C:\Program Files\Microsoft Visual C++ Toolkit 2003\include\math.h(572):
or       'float pow(float,int)'
        C:\Program Files\Microsoft Visual C++ Toolkit 2003\include\math.h(570):
or       'float pow(float,float)'
        C:\Program Files\Microsoft Visual C++ Toolkit 2003\include\math.h(534):
or       'double pow(int,int)'
        C:\Program Files\Microsoft Visual C++ Toolkit 2003\include\math.h(532):
or       'double pow(double,int)'
        C:\Program Files\Microsoft Visual C++ Toolkit 2003\include\math.h(195):
or       'double pow(double,double)'
        while trying to match the argument list '(int, double)'
windchill.cpp(49) : warning C4244: '=' : conversion from 'double' to 'int', poss
ible loss of data
windchill.cpp(51) : warning C4310: cast truncates constant value
Press any key to continue . . .
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 13.10.3077 for 80x86
Copyright (C) Microsoft Corporation 1984-2002. All rights reserved.


also I need dacs4w32.lib 
Do you have?
Your code and your skills will be assimilated. Your programming language is irrelevant.
We are the ASM Borg and you will become part of us. Compile and be assembled.

herge

 Hi Heather:

#include <cmath>
This should get rid of pow error I hope.

Note there is a c in front of math.
so it is cmath NOT math.

I do not have dacs4w32.lib on my
system so I can't give it to you.

Regards herge
Regards herge
Read "Slow Death by Rubber Duck"
for chemical Laughs.

hfheatherfox07

Quote from: herge on February 22, 2013, 05:50:22 PM

Hi Heather:

#include <cmath>
This should get rid of pow error I hope.

Regards herge

This is crazy ....
You have that in your original source
:dazzled:
Forget it I will stick to masm .....
Your code and your skills will be assimilated. Your programming language is irrelevant.
We are the ASM Borg and you will become part of us. Compile and be assembled.

herge


Hi heather:

look at the very first entry and check the includes
cmath is there.

regards herge
Regards herge
Read "Slow Death by Rubber Duck"
for chemical Laughs.

hfheatherfox07

Quote from: herge on February 22, 2013, 06:06:32 PM

Hi heather:

look at the very first entry and check the includes
cmath is there.

regards herge

LOL
That what I was saying
Your code and your skills will be assimilated. Your programming language is irrelevant.
We are the ASM Borg and you will become part of us. Compile and be assembled.