Jump to content

Game of Life in C++

- - - - -

  • Please log in to reply
7 replies to this topic

#1
Beeko

Beeko

    Learning Programmer

  • Members
  • PipPipPipPip
  • 101 posts
Hey guys, ya it's been really a while :D
I'v just got a new Program am supposed to make, It is a Game Called "The Game of Life".
Googled it, but I have absolutely NO Idea how it works ..... It'd be great if someone could explain it to me please? :D.

BTW, like... 2 days ago, I wanted to make a Program that reads the PC's time and Date and Prints them on the screen, Googled for such a function for 2 Hours, came up with Nada. Any Ideas?

Best Regards,
Beeko.

#2
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,118 posts
  • Location:Vancouver, Eh! Cleverness: 200
@1 http://en.wikipedia....e_of_Life#Rules (4 rules)
@2:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main(void)
{
    struct tm *current;
    time_t now;
    
    time(&now);
    current = localtime(&now);

    printf("the time is %i:%i:%i\n", current->tm_hour, current->tm_min, current->tm_sec);

    exit(EXIT_SUCCESS);
}

Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.

#3
artificial

artificial

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 624 posts
If you have more question about time, look at this: Link

Greets,
artificial
Sometimes words ain't enough to express something. That's why computer scientists use double words.

#4
Beeko

Beeko

    Learning Programmer

  • Members
  • PipPipPipPip
  • 101 posts
1- That is a different game of life,I meant The game of life, invented by the mathematician John H. Conway.
2-
#include <stdio.h>

#include <stdlib.h>

#include <time.h>


int main(void)

{

    struct tm *current; [COLOR="red"]//why did u make a struct? And whats with the Pointer? And isnt Structs supposed to be defined above the main?[/COLOR]

    time_t now;

    

    time(&now);

    current = localtime(&now);


    printf("the time is %i:%i:%i\n", current->tm_hour, current->tm_min, current->tm_sec); [COLOR="red"]//wth is this line? :D[/COLOR]


    exit(EXIT_SUCCESS); [COLOR="red"]//same?[/COLOR]

}


#5
Flying Dutchman

Flying Dutchman

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 889 posts
  • Location:::1
struct tm *current;
In C, or some versions of it, you have to type struct infront of it, and sometimes you may see something like this:
typedef struct myStruct myStruct;
This just makes it easier - you don't have to type struct anymore.
A conclusion is where you got tired of thinking.
#define class struct    // All is public.

#6
Beeko

Beeko

    Learning Programmer

  • Members
  • PipPipPipPip
  • 101 posts
I think I forgot to mention am working on C++? :D

#7
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,118 posts
  • Location:Vancouver, Eh! Cleverness: 200
I did link to Conway's game and the rules.

Beeko said:

I think I forgot to mention am working on C++? :D

ctime in C++ uses C's time library (time.h), C++ is based on C.
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.

#8
Beeko

Beeko

    Learning Programmer

  • Members
  • PipPipPipPip
  • 101 posts
Yes i know that but the code he Gave me doesnt make any sense any more xD




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users