|
|
I was trying to generate a random number between a min and max.
I would pass the double min and double max to the function and generate a number between the 2.
this is what I was trying to do:
thanks,
sj
I get an wrror though that says there is a double on either the right or left side.
<br />
double d = min + (double)rand() / RAND_MAX;
for(int i = 0; i < 100; i++){ <br />
<br />
}<br />
|
|
|
|
|
For a range of 0.0 to 1.0 use
double d = (double)rand() / (double)RAND_MAX;
You can then scale and offset the value to get it within the desired range.
The Ten Commandments For C Programmers
|
|
|
|
|
How's this for a hack?
#pragma pack (push, 1)
union
{
double d;
struct
{
short a;
short b;
short c;
short d;
} s;
} u;
#pragma pack (pop)
u.s.a = rand();
u.s.b = rand();
u.s.c = rand();
u.s.d = rand();
double Random = u.d;
Sonork 100.11743 Chicken Little
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
Within you lies the power for good - Use it!
|
|
|
|
|
That will generate crashes.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
care to explain why?
Sonork 100.11743 Chicken Little
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
Within you lies the power for good - Use it!
|
|
|
|
|
scolinks, what you did requires a person to enter an integer and then press the enter key. this poses 2 problems:
1. the user has to enter a key, then hit enter, where as _getch() just requires a keypress
2. if the user enters something other than a number, say, the letter 'q' the program will screw up and yell at you.
|
|
|
|
|
I'm still having the same problem. I did try the _getch(); at the end of my simple program and it compiled ok, but the stand alone .exe flashes for a brief second and then vanishes. I created a simple console default "hello world" program. The final release version will not stay open. However, it works ok in VC++. What could be the problem? I didn't see any property options to choose from on this.
Thanks
|
|
|
|
|
Just try to compile this code:
<br />
#include <iostream><br />
#include <conio.h>
using namespace std;<br />
<br />
int main()<br />
{<br />
cout << "Test" << endl;<br />
<br />
cout << "Press any key to return to system..." << endl;<br />
<br />
int Test = _getch();<br />
<br />
return 0;<br />
}<br />
This works on my machine - and on yours?
|
|
|
|
|
Can someone tell me how to move the cursor to the bottom of a rich edit control please?
|
|
|
|
|
This should work:
int iLength = RichEditCtrl.GetTextLength();
CHARRANGE nRange = { iLength, iLength };
RichEditCtrl.SetSel( nRange );
This sets the selection to the end of the string. If you want it to scroll to that area, I'm not sure of the API.
Wrongway
|
|
|
|
|
|
Hi!
I am a beginner and I have a problem!
I am using the DHTML edit control to let the user enter his/her text. After that he or she clicks on a button and this calls a function. I managed to write a function which reads the text line by line, adds infront of and after each line a Document.write(' and ') and saves it on a file. Well my program works fine if the user writes only one line but if it writes more than one my code doesnt work fine any more because it adds the ') after making a new line!
The users entry just like on the control:
Hi! I am your user.
How are you?
And my program makes this (it can make it correctly if there is only one line to render!):
document.write('Hi! I am your user
')
document.write('How are you?
')
and a webpage with a javascript code like this gives an "undetermined string blabla error!".
Why does it puts the ') after making a newline? Does the dhtml control add something to the text to signal a newline or .....? very
Can someone help me?
please....
Thank you for your future answers!
|
|
|
|
|
What function are you using to read each line from the edit control?
|
|
|
|
|
for example, student is a struct, student *std is defined in class CApp. how can I use std in class CDlg?
thanks!;P
|
|
|
|
|
Have a third class which holds this information, and query it from both of your original classes.
Or, have a global instance of the structure, and reference it using EXTERN CAPP::STUDENT *std
|
|
|
|
|
thank you very much!! i solved it !
|
|
|
|
|
Ok, an instance of the student struct is owned by your CApp object. Yes? Does the CApp object also own the instance of CDlg? If so, when the CApp object creates the CDlg object, it can pass a pointer to the student struct in CDlg's constructor.
|
|
|
|
|
I'm trying to pass a vector (of strings) by reference into a function that returns the vector of strings.
I have
vector<string> combovectorwrite(vector<string> $values, int val_num)
vector<string> is the return type, combovector is the name of the function, vector<string> $values is the name/definition of vector i'm passing into the function.
i've tried doing this before and failed miserably, i haven't yet figured out a way to do it. anyone have any tips?
|
|
|
|
|
Are you using STL?
For STL you would do:
vector<string> combovectorwrite(vector<string>& values, int val_num)
{
vector<string> resultantVector;
return resultantVector;
}
Is that what you were looking for?
-Nathan
---------------------------
Hmmm... what's a signature?
|
|
|
|
|
thanks. for some reason, i had something similar to that but it didnt work.
|
|
|
|
|
I built a simple Win32 program but it gives me the following message...I'm not sure what's wrong. I did the same program before and it worked, now something went wrong.
Linking...
LIBCD.lib(wincrt0.obj) : error LNK2001: unresolved external symbol _WinMain@16
Debug/Program_1.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
Program_1.exe - 2 error(s), 0 warning(s)
|
|
|
|
|
try this : http://www.cryer.co.uk/brian/mswinswdev/msdev_lnk2001ueswm.htm
also, did you create an empty, win32 console application when you created the project?
|
|
|
|
|
Check the libraries you added to your project. You might have made a mistake while adding one.
|
|
|
|
|
check the link property sheet in the Project settings dialog box,
to see if something go wrong with the /subsystem: option.
Just a try. May u good luck.
|
|
|
|