|
---Mark--- wrote:
I am a beginer, what can I say
There's nothing wrong with that. We were (and still are in many ways) all beginners at one point.
While I don't have a working program, I can give you a hint to get you going: use the rand() function to obtain a random number. Restrict the random number to the interval [1..6] by using the % operator.
/ravi
My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
Still working on my program.
And here is what I got so far:
#include <stdio.h>
#include <stdlib.h>
void showone();
void showtwo();
void showthree();
void showfour();
void showfive();
void showsix();
char getans();
void printlines(int n);
main()
{
int r;
char ans;
ans = getans();
while(ans== 'y')
{
r = rand()%6 + 1;
printlines(2);
if (r==1) showone();
if (r==2) showtwo();
if (r==3) showthree();
if (r==4) showfour();
if (r==5) showfive();
if (r==6) showsix();
printlines(2);
}
printlines(2);
}
char getans()
{
int ans;
printf("Throw y/n ?");
ans = -1;
while (ans == -1)
{
ans=getchar();
}
return ans;
}
void printlines(int n)
{
int i;
for(i=1 ; i<=n ; i++) printf("\n");
}
void showone()
{
printf("\n * \n");
}
void showtwo()
{
printf(" * \n\n");
printf(" * \n");
}
void showthree()
{
printf(" * \n");
printf(" * \n");
printf(" *\n");
}
void showfour()
{
printf(" * * \n\n");
printf(" * * \n");
}
void showfive()
{
printf(" * * \n");
printf(" * \n");
printf(" * * \n");
}
void showsix()
{
int i;
for(i=1 ; i>=3 ; i++) printf(" * * \n");
}
The problem I am having is I can't figure how to make it loop back to the y/n. How it is now it goes on forever. How can I make it ask "Throw y/n" each time?
Thanks
-Mark
As you journey through life take a minute every now and then to give a thought for the other fellow.
He could be plotting something.-Hagar the Horrible
|
|
|
|
|
Try changing
ans = getans();<br />
<br />
while(ans== 'y')<br />
{<br />
...<br />
}
to
while(getans()=='y')<br />
{<br />
...<br />
}
That should make it ask the question each time.
|
|
|
|
|
Hi,
Try doing this:
void showone();
void showtwo();
void showthree();
void showfour();
void showfive();
void showsix();
char getans();
void printlines(int n);
void main()
{
int r;
char ans;
srand( (unsigned)time( NULL ) );
ans = getans();
while(ans== 'y')
{
r = rand()%6 + 1;
printlines(2);
if (r==1) showone();
if (r==2) showtwo();
if (r==3) showthree();
if (r==4) showfour();
if (r==5) showfive();
if (r==6) showsix();
printlines(2);
ans = getans();
}
printlines(2);
}
char getans()
{
int ans;
fflush(stdin );
printf("Throw y/n ?");
ans = -1;
while (ans == -1)
{
ans=getchar();
}
return ans;
}
void printlines(int n)
{
int i;
for(i=1 ; i<=n ; i++) printf("\n");
}
void showone()
{
printf("\n * \n");
}
void showtwo()
{
printf(" * \n\n");
printf(" * \n");
}
void showthree()
{
printf(" * \n");
printf(" * \n");
printf(" *\n");
}
void showfour()
{
printf(" * * \n\n");
printf(" * * \n");
}
void showfive()
{
printf(" * * \n");
printf(" * \n");
printf(" * * \n");
}
void showsix()
{
int i;
for(i=1 ; i<=3 ; i++) printf(" * * \n");
}
Regards,
Mahadevan
|
|
|
|
|
What does the fflush() function do?
Thanks
-Mark
As you journey through life take a minute every now and then to give a thought for the other fellow.
He could be plotting something.-Hagar the Horrible
|
|
|
|
|
The fflush() function flushes the console input before u use getchar().
|
|
|
|
|
Basicly what the other two guys said, except you might want a do/while loop and not a standard while loop. Look it up, the do while will always give you one roll before asking if you want to roll again.
I recomend "the art of computer programing" by Donald Knuth http://www-cs-faculty.stanford.edu/~knuth/taocp.html which describes random numbers in far more detail than you ever thought possible. These are unfortuntly advanced books, completing one should be considered equivelant to a PHD! Still you should be aware of them, and (if you can afford them) have them on the bookshelf.
What I want you to get from these books: random numbers have been the most popular subject in advanced computer science since before there was comptuer science. I estimate that 1/3rd of all PHDs in computer science studied random numbers (and there is still pleny of room for more study) Your simple program is not complete until you understand something about random numbers.
In particular, the most common implimentation of rand() will ALWAYS give a odd-even-odd-even sequence! This is not something you want I'm going to guess. Issues like this are what seperate simple programs like yours (that look just fine) from complex programs done by an expert. You can never know it all, but I've just given you an area to look.
|
|
|
|
|
I'm having trouble giving command line arguments to VS.NET 2003 in debug mode without opening a prompt.
My debugging properties are as follows.
Command: cmd.exe
Command Arguments: -input test.scn -output test.tga.
(basically input scene description file and output image file)
When I start the debugger, argc is always 1, which means only the executable name was found in the command line. So my arguments are never read. I tried setting input to "test.scn", and output to "test.tga" in main(), same result (input and output are c++ strings in the main function). I also tried setting the working directory to .\Debug. without success. The test.scn file is in my project's Debug folder.
What am I missing?
Cheers, blackmesa.
|
|
|
|
|
Not sure about VS.NET 2003, but under VS6 you can specify command-line parameters under the Project Settings...
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
Well I'm specifying the arguments from the Project Properties, which is pretty much the equivalent of Project Settings under VC 6.
Cheers, blackmesa.
|
|
|
|
|
Hello,
I am try to create a virtual desktop on windows 98SE and 2000.
Basically what I'm trying to do is to set the desktop to be twice as wide as the screen resolution. e.g. 2048x768 for the desktop and 1024x768 for the minitor resolution. Windows should then allow you to simple scroll the monitor (view port) left/right over the desktop... Easy..
So what I have tried is the SystemParametersInfo() call with the SPI_SETWORKAREA flag. However this call returns NULL, so I called GetlastError() and this returns 87 (INVALIDE_PARAMETER) This I think is due to the security mask ?? any ideas please..
Or better still have anyone written this and has some source.
Brgds Ian Knight
|
|
|
|
|
Hello Friends,
How can I know the users of the system and which is the header file one has to go through for knowing the system properties like type of OS, users of the system, network card and its address etc.,
Thank you
Neelesh K J Jain.
|
|
|
|
|
|
Hello,
When I compile the code at realese I get;
error C2065: 'IDD_LOGIN' : undeclared identifier
But when I run it in debug I don't get it.
How can I fix this?. Please help me.
|
|
|
|
|
Looks like you may have put your #include "resource.h" line (or the line that #include s your dialog's .h file) between the #ifdef DEBUG .. #endif block. It needs to be outside.
/ravi
My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
where can i change that??
|
|
|
|
|
Well, it's a little hard to say without having had the chance to look at any of your source code. My guess is the problem lies in the .cpp file of a dialog class.
/ravi
My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
Well this is the error I get,
error C2065: 'IDD_LOGIN' : undeclared identifier
error C2057: expected constant expression
IDD_LOGIN is not the main dialog window,
but I don't now way it happends. But it only happends when I make a Release version.
|
|
|
|
|
Like I said, it may help if you posted some source code.
/ravi
My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
Well I can't send some code *Company code* but here is some
class CNetEyeLogin : public CDialog
{
// Construction
public:
BOOL GetProgramDir(LPTSTR str, DWORD dwSize);
CString m_PassOK;
void OnCancel();
void OnOK();
CNetEyeLogin(CWnd* pParent = NULL); // standard constructor
// Dialog Data
//{{AFX_DATA(CNetEyeLogin)
enum { IDD = IDD_LOGIN }; // Here is whare I get the error
CString m_Pass;
// NOTE: the ClassWizard will add data members here
//}}AFX_DATA
Like a said enum { IDD = IDD_LOGIN }; is where I get the error.
I Hope this help you a little bit.
|
|
|
|
|
So is the #include "resource.h" line missing/misplaced (as I mentioned in my original reply)?
/ravi
My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
#include "resource.h" is set in the main dialog *.h file
like this;
// NetEye.h : main header file for the NETEYE application
//
#if !defined(AFX_NETEYE_H__B769970B_B16E_4786_8362_1DEB876E5438__INCLUDED_)
#define AFX_NETEYE_H__B769970B_B16E_4786_8362_1DEB876E5438__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#ifndef __AFXWIN_H__
#error include 'stdafx.h' before including this file for PCH
#endif
#include "resource.h" // main symbols
/////////////////////////////////////////////////////////////////////////////
// CNetEyeApp:
// See NetEye.cpp for the implementation of this class
I don't have it in the dialog *.h file that makes the error.
|
|
|
|
|
Larsson wrote:
I don't have it in the dialog *.h file that makes the error.
Try adding it.
/ravi
My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
He he he ,
Well it works thank !)
|
|
|
|
|
i have this class :
using System;<br />
using System.Windows.Forms ;<br />
using System.Data.SqlTypes ;<br />
using System.Data ;<br />
using System.ComponentModel;<br />
<br />
namespace WindowsApplication1<br />
{<br />
public class DateTextBox : TextBox<br />
{<br />
<br />
public DataSet1 myDataSet ;<br />
<br />
private SqlDateTime m_dateValue ;<br />
[Bindable(true)]<br />
public SqlDateTime DateValue<br />
{<br />
get{return m_dateValue;}<br />
set{m_dateValue=value ;}<br />
}<br />
<br />
public DateTextBox()<br />
{<br />
}<br />
}<br />
}
when i want to bind DateValue property of above class to SqlDateTime like this :
dateTextBox1.DataBindings.Add("DateValue",dataSet11.stud,"date1") ;
this runtime error display :
An unhandled exception of type 'System.InvalidCastException' occurred in mscorlib.dll
Additional information: Invalid cast from System.DBNull to System.Data.SqlTypes.SqlDateTime.
please help ,please.
|
|
|
|