|
I wanted to add one more awesome thank you to you and everyone else who helped. I finished my "Video Poker" game at 7:30pm on Sunday, it was due at midnight. I put in over 35 hours between designing the menu, debugging, reading and writing to files, converting repeated sections into separate function and header files, debugging, doing the base code, and debugging.
After a solid 800 lines of code for a final project in my very first actual programming class... I get 600 out of a possible 600 points! And a very special, "FYI, It is very rare to get 100% - Congratulations!"
I wanted to respond back because I wouldn't have gotten that grade without the help I got here. It opened a lot of doors when I was struggling and also became a gateway to understanding a few other things I was missing out on. Thanks again everybody! Your tutoring and help is very much appreciated!
|
|
|
|
|
you're welcome. That is what CodeProject is all about, giving you answers to specific questions, some hints, and the stimulus to study, persevere, google, and try.
congrats again.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
It's nice to see the lightbulb form in slow motion!
Many of these things are hard to teach, or to initially understand. Once your brain makes the click sound, it's hard to see how people *don't* understand.
I've done quite a lot of training in the past, and the hardest bit was putting yourself back in the position of the trainees.
Iain.
I have now moved to Sweden for love (awwww).
|
|
|
|
|
Hi Frank,
Just to expand a bit on Luc's comment above, there's usually a simpler way of doing things when you see repeated code. Have a look at the facilities provided by the <algorithm> header, you'll find plenty of ways to simplify loops. In your case you're transforming the contents of one collection into the contents of another which is exactly what std::transform does.
So taking Luc's comments one stage further you can do most of what you were trying to do with your initialisation loops in two lines:
std::transform( hand, hand + 5, handColumn, []( int n ){ return n / 13; } );
std::transform( hand, hand + 5, handRow, []( int n ){ return n % 13; } );
The arguments to std::transform are a bit weird looking if you've never seen them before:
- the first two describe where you want to get the data to transform from
- the third describes where you want to put the transformed data
- the fourth describes how you want to transform it
So in both cases you're wanting to operate on data from hand[ 0 ] to hand[ 5 ] (not including hand[ 5 ]) and stick the transformed data into handRow or handColumn starting at the beginning. The last parameter is a lambda (it starts with empty square brackets)that says what you want the tranformation to be division by 13 in the first case and modulo by 13 in the second case.
(lambda's are inline objects that behave like function calls. They're part of the C++0x standard - VC++ 2010 and gcc 4.4 support them though so it's easy to get a free compiler that knows about them.)
Going a bit further... even with these changes it takes a bit of looking at the code to work out what's going on. As far as I can tell you're taking an integer representation of a playing card and decoding it into an integer representation of a suit and a card face. Both aren't that obvious - it looks like you're missing a few abstractions in your code. If you had these abstractions you wouldn't be worrying about decoding the card's suit and face value from an integer, it'd just happen.
Anyway, I can witter on a bit more if you want - otherwise the important message to take from this is handcrafted loops are often not as effective as taking an algorithm from <algorithm> and applying it.
Cheers,
Ash
|
|
|
|
|
Yeah, The problem I'm running into, is I only have a portion of C programming knowledge. We're only about halfway through the book with this class and this is the final program due tomorrow... er now today. I've been working on it for a while, but trying to get the win conditions spelled out has been quite difficult. I worked on this project almost 12 hours yesterday, and now going to hit it some more today. Hopefully I can get it done!
|
|
|
|
|
Hi,
I'm trying to port a 3d game for Linux into Windows. I'm stuck right now, because the code has the commands ioperm, outb, and fmod which are Linux only. I'm using Visual Studio 2005. There are dlls out there but I don't know how to implement them. I have a screenshot:
http://forum.freegamedev.net/download/file.php?id=416&mode=view[^]
Can you help me?
|
|
|
|
|
|
If it was, I would know. I've been contributing to it (SuperTuxKart) for a year now.
I found the fmod isn't Linux-only... But I try putting double, float, and long double and none of them work.
|
|
|
|
|
fmod must work on Windows .
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
The error you are getting for fmod indicates it can't decide which of the 3 versions of fmod that it should use.
you will need to explicitly declare or cast the type of your variable for the fmod call.
ioperm and outb are for port access on Linux.
ioperm gives access to the serial ports, which you may or may not need to call on Windows based on your security settings.
outb writes a byte to the specified port. You can open a serial port with a call to CreateFile, and specify the name of the port, such as "COM2". Then use WriteFile to write a single byte. Depending on how complicated the serial port access is in the game, you may want to look up the "Communication Functions" such as SetupComm.
Good Luck
|
|
|
|
|
I put in long double, double, and float in front of fmod and none of them work.
outb: you lost me at CreateFile.... I don't know much of anything about programming.
|
|
|
|
|
I get the error "type unexpected". for fmod prefixes. What should I do?
|
|
|
|
|
Hello, I am trying to interact dynamically with a 3rd party application dialog. This dialog has the usual OK and CANCEL buttons and an edit box. I want to be able to set the text in this edit box. I have managed to enumerate the handle of the dialog, but can't see how to find the ID of the edit box in order to get it's handle and thereby set the text. Perhaps someone can point me in the right direction !!
Doug
|
|
|
|
|
You can use the call GetWindow, and use the GW_CHILD flag to start out with. Then test for the type of class of that window with a call to GetClassName. You are looking for the "EDIT" class. When you find a window whose class matches that criteria, you will have the handle to the Edit control.
After testing each handle, if you have not found the correct window, then call for the next child window of the dialog, using the child window handle from the previous call to GetWindow, and this time use the GW_HWNDNEXT flag.
Ex.
HINSTANCE hInst;
HWND hDlg;
TCHAR className[_MAX_PATH];
...
HWND hChildWnd = ::GetWindow(hDlg, GW_CHILD);
while (hChildWnd != NULL)
{
WNDCLASS wndClass;
::GetClassInfo(hChildWnd, className, sizeof(className));
if (0 == ::_tcscmp(className, _T("EDIT"))
{
// This is the window handle that you want.
// Record the window handle here or do your special processing.
...
break;
}
hChildWnd = ::GetWindow(hChildWnd, GW_HWNDNEXT);
}
If there are more than one edit controls on the dialog things get a bit trickier.
You should look at the tool Spy++ that came with Visual Studio, it will allow you to peek at all of the important data regarding the windows, its class type, id etc.
|
|
|
|
|
Hi Paul, What a brilliantly comprehensive answer !
Very many thanks !
Doug
|
|
|
|
|
Hello all;
I write a simple program to calculate quadratic equation with function in c.
<br />
#include <stdio.h><br />
#include <math.h><br />
float solver(float a,float b, float c){<br />
float delta,x1,x2;<br />
delta=(b*b)-4*a*c;<br />
x1=(-b+sqrt(delta))/2*a;<br />
x2=(-b-sqrt(delta))/2*a;<br />
return(x1,x2);<br />
}<br />
void main(){<br />
float a,b,c,d; <br />
printf("a = ");<br />
scanf("%f", &a);<br />
printf("b = ");<br />
scanf("%f", &b);<br />
printf("c = ");<br />
scanf("%f", &c);<br />
printf("%f\n%f",solver(a,b,c));<br />
<br />
}
the result for a=1,b=2,a=1 is
-1.00000
0.00000
and for any other numbers the second result is 0.00000
Where is the problem.
Thanks anyone help me.
|
|
|
|
|
hasani2007 wrote: printf("%f\n%f",solver(a,b,c));
-here you try to print 2 float values but feed printf only with one.
hasani2007 wrote: return(x1,x2);
-this is not the way to return 2 values from a function (i guess this is what you are tryin to do), use output parameters, a struct, global variables, ..., e.g like:
void solver(float a,float b, float c, float &outX1, float &outX2){
...
outX1 = x1;
outX2 = x2;
}
...
float x1, x2;
solver(a,b,c,x1,x2)
printf("%f\n%f",x1,x2);
...
or
struct result
{
float x1;
float x2;
};
result solver(float a,float b, float c){
...
result res;
res.x1 = x1;
res.x2 = x2;
return res;
}
...
result res = solver(a,b,c);
printf("%f\n%f",res.x1,res.x2);
...
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Sometimes you just have to hate coding to do it well. <
|
|
|
|
|
I'm not an expert in the details of C/C++, but the solver function definition shows a float should be returned and it appears you're trying to return a tuple.
CQ de W5ALT
Walt Fair, Jr., P. E.
Comport Computing
Specializing in Technical Engineering Software
|
|
|
|
|
Your program to calculate quadratic equations with .
Input MUST have the format:
AX2 + BX + C = 0
EXAMPLE: input the equation
2X2 + 4X -30 = 0 as:
A= 2 B= 4 C= -30
The answers should be 3 and -5.
x1=3
x2=-5
#include <stdio.h>
#include <math.h>
float x1,x2;
bool solver(float a,float b, float c)
{
float delta = sqrt( (b*b) - (4*a*c) );
if (!a) return false;
x1 = ( -b + delta)/(2*a);
x2 = ( -b - delta)/(2*a);
return true;
}
int main()
{
float a=2,
b=4,
c=-30;
if ( solver(a, b ,c) ) printf("x1=%f\nx2=%f\n",x1,x2);
return 0;
}
..
|
|
|
|
|
Please, don't give such a bad solution!!!
I've adjusted it to avoid global variables:
#include <stdio.h>
#include <math.h>
bool solver(float a,float b, float c, float &x1, float &x2)
{
float delta = sqrt( (b*b) - (4*a*c) );
if (!a) return false;
x1 = ( -b + delta)/(2*a);
x2 = ( -b - delta)/(2*a);
return true;
}
int main()
{
float a=2,
b=4,
c=-30;
float x1,x2;
if ( solver(a, b ,c, x1, x2) ) printf("x1=%f\nx2=%f\n",x1,x2);
return 0;
}
|
|
|
|
|
|
I want to add a comment to Code-o-mat's reply. The value of the expression (x1,x2) is the value of x2. You were trying to return two float values, however, you did not pay attention to the "," operator, and thought that (x1,x2) represents the two value you wanted to return. The compiler actually returned just the value of x2. Please read the documentation of C/C++ for the operator ",".
|
|
|
|
|
At 5:35 on the 13th of May 2010, AbhiHcl wrote:
>>>
>>> Hi,
>>>
>>> Can I use single button for more than one behaviour.
>>> For example one button is devide into 2 parts,
>>> If I click on first part minus operation should be performed
>>> and click on second part + opeartion should be performed.
>>>
>>>
Yes you can use one single button for more than one behaviour.
Here is how.
If you have the coordinates of a point in device coordinates
and want to find the corresponding position in logcal view -
use CDC::DPtoLP to convert the device coordinates to logcal coordinates.
Call on OnPrepareDC first to set the mapping mode and factor.
For example: Here is a WM_LEFTBUTTONDOWN handler that performs a simple hit test
to determine whether the click point lies in the upper or lower half of the logcal view.
CPoint objects passed to OnLButtonDown and other mouse message handlers
always contain device coordinates so conversion is essential.
void CMyView::OnLButtonDown(UINT nFlags, CPoint Point)
{
CPoint pos=Point;
CClientDC dc (this);
OnPrepareDC(&dc);
dc.DPtoLP(&pos);
CSize size=GetTotalSize();
if(::abs( pos.y ) < (size.cy/2) )
{
}
else
{
}
}
...
|
|
|
|
|
i want to write ini file by WritePrivateProfileString function with out and delay. currently it take 2 to 3 seconds beacuse this function is work on cache file of ini file.
if system is being restart that time then we are unable to retrive information .
please suggest me how can i update ini file
|
|
|
|
|
Try WritePrivateProfileString(NULL, NULL, NULL, L"inifile.ini")
|
|
|
|
|