Random Number generation is easy but when you call rand() you only get a number from an array.To get true random numbers you have to seed that array using srand();
call srand(GetTickCount());Then you start getting random numbers.
Random Number generation is easy but when you call rand() you only get a number from an array.To get true random numbers you have to seed that array using srand();
call srand(GetTickCount());Then you start getting random numbers.
/*
A Little help with the benchmarking.(C++)
benchmark.h
Notes:
None too perfect,not even tested.This was just to give you an
idea as to how you could go about making a benchmarking system
Btw,It should work :).
The class need not be used,only important and tested thing is the
GetTickCountM13();Use it to make your own system.We will need this
from part II.
*/
word *clock=(word *)0x0000046C;
double GetTickCoutM13()
{
return (double)*clock;
}
Class Benchmark_system
{
private:
ofstream log;
double tick;
public:
Benchmark_system();
~Benchmark_system();
void init(char*);
void start();
void end();
};
Benchmark_system::Benchmark_system()
{
tick = 0;
}
Benchmark_system::~Benchmark_system()
{
log.close();
}
void Benchmark_system::init(char* file)
{
log.open(file,ios::trunc);
log<<"\nBenchmarking System 0.1, by Firenet\nhttp://xlock.hostcubix.com\n\n";
}
void start()
{
tick = GetTickCoutM13();
}
void end()
{
log<<"\nTicks taken: "<<(tick-GetTickCoutM13());
}
Mode13h
The Beginning of 3D/2D Graphics
Intro
Lots of people want to know how to do graphics but find most APIs like
OpenGL, DirectX etc too complex for a beginner, especially as they involve GUI code which follows a different approach from the simple dos programming Here, I will present a simple graphics mode, which can be easily used via dos console programming
What I will be covering
Part 1:Introduction to Mode13h (this part)
Part 2:Blazing:Lets speed up and burn (algorithms,double buffering)
Part 3:Dangers and Protection Systems (wait and see)
Part 4:Bitmap Loading and Animation (woooooo!!!!)
Part 5:Assembler,Let's go faster (world of supersonics,C++ code)
Part 6:Palette fun (let the artist live)
Part 7:Intro to 3D (::::::::::::::::)
Part 8:3D Star Fields (weee!!!!)
Part 9:Wrapup (end,alternate techs)
Ok, this series will take sometime or so. Maybe weekly updates. We go
slow in this article. Part 2 will be larger and contain code.
History of Mode13h
Here's a quote by a 3D programmer, Jacco Bikker (The Phantom):
In the old days, there was DOS. And in DOS, there was mode 13. Once
initialized, the unsuspecting coder could write to video memory, starting
at a fixed address, A0000 if I am correct. All this didn't block the computer, and worked on virtually every VGA card in the world. The mode allowed for output of 256 color graphics, and that was just fine, if you did it well.But then something really bad …
Easy enough :D,
Include conio.h and put a getch() before return 0; in main().getch() waits for the user to press a key and it returns that value.
So
char ch;
ch = getch();
cout<<"User Pressed :"<<ch<<" Int value:"<<(int)ch;
So if the user pressed enter the int value is 13, if it is 'A' the int value is 64 i.e the ascii values of the key pressed.
Helps?
Hey go to the tutorials fourm and check out the tut for file i/o using fstream.(C++)
Here's the link:
http://www.daniweb.com/techtalkforums/thread6542.html
*Yawn*, me too.Who cares ???.We will have to use what ever the policy making companies shove at us.Yup it's quite too the OpenSource is only open before money comes in.It's like water,can dissolve anything given enough time.Brrr
<b>Resistance is futile.</b>
Nah......,You can do that till you are dead :D,and even then you can leave followers to do your work.
So after you are gone,what do you care :D .
Sorry we cant.This is a fourm for programming discussions not for getting your homework done by others.We dont do home work.We just help each other solve problems we enconter.
Go ahead and search at www.google.com
So there is always cin>>.:D
You are most welcome.I dont know the exactly if there is any directory path size limit but you can be quite sure the almost no one will use a path which is more than a 100 bytes.It's too long.:D
Yea, you can also use wincap, that library provides you with raw packet access and is portable.
Sorry Dude,we aint your homework doers.
Btw there was a previous post on a vending machine so you are in luck.
http://www.daniweb.com/techtalkforums/thread7183.html
[Huh,I feel I am copying some one,RoundRobin something .... Dani?]
Sorry, we are not your homework doers.
Anyway new and delete are tech info so here is an example
int *n=NULL;
n = new int [10];
if(n==NULL)cout<<"Error:Not enough Memory";
delete[] n;
If you use a new statement then you should always delete it else your comp will soon run out of ram. Brrrr (Memory leaks).
Using Standard C++ (98),eh?,Well the tut was in old C++ and I am still learning STL and the new C++ freatures.
reinterpret_cast<char *>(&p_Data): I belive this is the problem area.
Try:reinterpret_cast<char *>(p_Data)
I am not too sure :-| ,so you can even try static_cast<char *>.I really havent got around to using this yet.Better stick to (char*)&p_Data.
Here a file i/o tut (detailed :D)
http://www.daniweb.com/techtalkforums/thread6542.html
Once you have read a random word then you can go a head with the game
Look at something I wip up on the fly,may not be too correct
//headers
void show(char* s,bool *d,int len)
{
cout<<"\n\n";
for(int i=0;i<len;i++)
{
if(d[i])cout<<s[i]; //display the letter
else cout<<"_" //else the blank
}
}
bool check(char ch,char* s,bool *d,int len)
{
bool ret=false;
for(int i=0;i<len;i++)
{
if(s[i]==ch) ret = d[i] = true;
}
return ret;
}
void main()
{
char word[100]={"something"};
char hng={"HANGMAN*"};
char ch;
int wrong=0,max_wrong = 8;
int len = strlen(word);
bool *disp = new int [len];
for(int i=0;i<len;i++)
disp[i] = false;
do
{
show(word,disp,len); //show the word
cin>>ch;
if(check(ch,word,disp,len))
{
cout<<"\tCool you got a letter";
}
else
{
cout<<"\tSorry,wrong";
wrong++
}
}
}
while (wrong <= max_wrong);
cout<<"Thankyou Bye";
}
Ok it's go a few things missing for one thing it does not show you if you won or lose or choose a random word etc.I just wanted to show a way to display the stuff and hide letters.
Help?
Now this is a bit OS specific when it comes to raw packet sending.I really dont know if you can manually control ARP packets on a Windows PC (XP,2000,NT [you dont even get raw packet access on other windows vers]).
You can find *nix code easily on the net.(try send_arp.c).
Using Windows XP,eh?
If you want a tut on fstream look in the tutorial fourm :D
Graphics eh?
Well this is fun stuff but I would rather tell you to get fimiliar with C++ and OOP concepts like funtions,classes,structures,pointers,memory management etc... before getting to graphics.That way you will be able to do graphics more easily and with much less code.
OpenGL is a bit too much since you will have to do a bit of windows code.But you can sure try Mode13h.Its a very simple graphics mode and you can do it via dos mode without any windows GUI code.
Links
-----
http://www.brackeen.com/home/vga/ - a very good site for Mode13h programming
I dont know how to get into Mode13h in Dev-C++,but there is much info on the above site on Mode13h.You can use TurboC from Borland which is available for free,or even another compiler.
The steps to draw pixels are simple and the same once you find a way to get into Mode13h.Then you can use any algorithm to draw lines,circles,display bitmaps etc.
:)
Yea,we aint answering machines nor auto homework doers.We help out solving difficulties.
:),Have fun(Btw by welcome)
One thing is that you are doing nothing much about the file i/o.Can you explain what you mean by no output.
Check the tutorial fourm for a fstream file i/o tutorial,might help :D.
Finally something useful on SafeArray,thanks.
These are used to allocate memory dynamically.With these you get memory from the OS and point to that memory address with a pointer.
Presonally I use C++ new operator.
Eg.
Some_data_type *object;
object = (Some_data_type*)malloc(sizeof(Some_data_type),1);
that is to assign memory.
Then when you are finished with it:
free(object);
That's the general way to use it.
I dont think so,it will be of some use to someone,hey teachers usally accept a submission even if it a bit late.
You could try looking in *nix development fourms.Also try looking in google.You will definately find good info if you search properly.
Gee, you sure were in a hurry but the lack of full stops really mangles what you say.
This is not really a place to ask for homework answers.But I did look at your code and you use a lot of variables like a,b,c etc for what resonable puprose I cant guess.Also code is a bit messed up in the sense that it too packed where you calculate the vals so I could not understant it too much either.
But here's something :
Lesson1:Code clearly and use spaces and newlines.They will save your life when it comes to debugging.Noodle code is a death trap.(Your code is not too noodlely except in the if else part).
Lesson 2:Use funtions (I dont know if you know funtions)
Now your prob:One Idea would be to convert the entire amount in to the lowest denomintions availble(nickle?) and calulate using that.In the end convert it back to dollars and show what ever remanins as nickles.Dont bother with quaters unless you have to.
Not much but i could not understand you code nor what was you prob,nor do i have a compiler handy right now. :0
C or C++ though C++ is easier to use and much more object oriented.There are a lot of C/C++ compilers availabe.
Visual C++ is expensive and Borland is ok.There are free versions of both.
Choice ( A ) is the most accurate.There are more funtions getline can peform.
You can use structures
struct Dtime
{
int mins;
int years;
int days;
};
The to declare a variable:
dtime datetime;
And to assig values.
datetime.min = 10;
datetime.year = 2004;
Just use the var_name.member and you can do anything to them as would do to a normal int, char etc.
Even if you include main() in a header and dont declare main() in any other funtion the program will complie and work properly.Headers are just a way to organise code.
:-| ,huh more errors when you tried that.I would have thought that immpossible.It's allowed C++ syntax.Either you used it in a wrong way or the error was cause by something else.You did not post the errors though.
Can anyone say there is anything wrong with while(choice >=1 && choice <4) and if so why.
Good you fixed it.Now get going onto proper file i/o and log the stuff you need in an organised fasion.
Sure thing wolf, go ahead and learn C++ and maybe in a few months you can get into graphics programming.It's not tough (hey, if you get a pencil and know how to draw lines you can draw houses) but unless you know a good bit of the basics you will not understand many things.Unless you understand what you are doing you will not progress.
Hey guys now be careful not to modify your actual headers it's not safe.Bodb, nice of you to check it out but that kinda protection is usally related to memory modes or some sort of diffrence in the way the compiled program inteacts with the system or is compatable with.Now in this particular case it may complie well but I would still recommend you change the options on your complier when you are compliing your program.That way you will be able to avoid any errors during runtime due to illegally structured programs.
WAP stands for Write A Program I belive.Teachers commonly use that when they write on a board.
About you second question:
It easy enough if you think logically.How do you find the number of digits in a number,by counting ofcourse.Now how do you get a computer to count?
That can be done by removing digits one by one and that can be done by dividing the number by ten.Simple eh?
while(num > 0)
{
num = num/10;
no_of_digits++
}
Very simple.
I could not really understand your first question.
try doing this
int a,b,c,d;
scanf("%d%d%d",a,b,c);
d = a+b+c;
printf("The answer is:%d",d)
NEVER EVER GIVE UP
Oh,I din't give more links since I want you to search.
(Give a man bread today, he will be hungry tommorow.Teach him to fish and he will survive for a lifetime) or so the saying goes.
That way you will have your own questions and you will find you own answers and you will really progress.Best of luck
hello.
thanks to all of you for taking time to answer questions.
i just started learning c++ and i'm confused as to how graphics are added to a program.does c++ have graphical capabilities on it's own or does it need another program like Direct-x?
the graphics i make are tiles,32x32 BMP or Jpeg.
can i get an example of how to place one in a program, or , further information.
thanks.
Sorry to dash any high hopes you have but graphics is something you will only be able to do after you have much more knowledge in C++.
Actually C++ has it's own way of showing graphics through the operating system but at a very low level by drawing pixel by pixel.Actually everyting on screen drawn that way.
Now it would be boring to do that,so people made funtions to draw lines,then to draw boxes ,then to display text,and progress on to draw windows and all the stuff you see.
Now DirectX is not a program.It is just a library which helps you to draw and C++ version of it is available.At you current level you wont even be able to set it up on you compiler,sorry you reaching for the moon.
Good news you can learn more C++ and then go on to graphic within no time if you advance well.I just started 4-5 five months ago in game programming but I have 3 games aready done.Just because I know C++ well.
…Hey I think you guys are barking up the wrong tree.
scanf() works with options you sepecify.By options I mean all the stuff you specify in the " ".So it also means you can have multiple options too.
some options
-------------
%s string (char *)
%d int
%f float
you can also use scanf() like this ie how to specify multiple options
scanf("%d,%f",int_val,float_val);
Helps???
ok, then try using it like this.
#include <fstream.h>
void main()
{
ofstream file;
//your code
file.open("log.txt",ios::app);
file<<"what erver you want :-)";
file.close();
}
Try
while(Choice >= 1 && Choice <4)
Solve troubles ?
"radi.h" where can one find it eh?
Am I missing something?
:confused: Did you try including fstream.h
#include <fstream.h>
Hey not sleep(2000) bleek, sleep(4) might be a nice number if sleep() is the same for your complier as for mine.I use Borland C++ and sleep() counts in seconds.
There is also delay(int) funtion.It counts in some unit lower than a second.
#include <stdlib.h>
#include <dos.h>
(I dont know which compiler you guys use)
:surprised :confused:
Yes they are quite the same and mainly an organising tool.They can be used for various purposes from just organisation to linking to static libs.
What's funny is somethings are so used to people use them without a thought and dont document it.(like sugar,does anyone ask what it is)
Try these :-)
http://www.cplusplus.com/doc/ansi/hfiles.html
http://www.doc.ic.ac.uk/lab/secondyear/cstyle/node5.html
http://www.iota-six.co.uk/c/j2_creating_header_files_and_library_functions.asp
Tried Google?
http://www.google.com/search?hl=en&lr=&ie=UTF-8&safe=off&q=Using+C%2B%2B+SAFEARRAY&btnG=Search
You are right about it though.Not much info.But here is some interesting stuff.
To Kc0arf,
Not necessary I belive.Especially when only two conditions are being compared or multiple non dependants
if(condirion1 || condirion2 || condirion3)
it will be needed if you are going in for dependants
if(condirion1 || (condirion2 && condirion3) || condition4)
To Bleek,
What you say is very true.:-)
I guess I would agree with meabed.
No programmer is poor unless he calls himself a programmer and does not put any effort into programming.
Hello my poor c++ programmers
strcmp take two argument of type char * i.e array of character not char
i.e you can compare between
char *p = "SADDAM",l= "BOOSH";
cout << strcmp(p,l);
i hope you understand this thing
What makes you so rich abu_sager?
:!:
Just wanted to show how it works inside. It would sure help in understanding what goes on.
btw,what the use if all use something without knowing how it works
use if, if else and else.You can have multiple checks in a if statement
if(condition == true || condition < high)
if(condition == true && condition < high)