Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Programming some game

Name: Anonymous 2007-03-16 11:30 ID:+Cao99ew

Okay.. i'm a noob at C and i'm trying to do some game.
It's a game for 2 players. The first player inputs 4 numbers. The 2nd player tries to guess which numbers those are by inputting numbers too. If there is a correct number in wrong order, 0 will print. If there is a correct number in correct order, 1 will print. Game will end if the 2nd player gets 1111 or uses up all 10 turns.

I can't understand the array stuff much.. help me.

Name: Anonymous 2007-03-17 15:27 ID:lwMb8DXj

>>39
zipWith?

Name: Anonymous 2007-03-17 15:43 ID:tbIcxepU

>>37
I told you, you need to add system("PAUSE"); at the end

Compiled with GCC using Code::Blocks you may need to add system("PAUSE"); at the end if you want the program to stop at the end

Name: Anonymous 2007-03-17 15:50 ID:OlBFoWxb

>>41
sigh

compareDigits _  [] = []
compareDigits xs ys = zipWith (\a b -> if a == b then 1
                       else if elem a ys then 0 else -1) xs ys


too bad i need ys in the anonymous function or this could be made pointless

Name: Ze Killer Of Poussin !SsWAPkwaM6 2007-03-17 16:06 ID:bpKL43Zg

>>42
system("PAUSE") IS NOT STANDARD SO YOU'RE WELCOME, MY DEAR FAGGOT, TO NOT LEARN BAD HABIT TO OUR FRIEND, HE SHALL PUT getchar() AT THE END OF MAIN OR LAUNCH IT FROM THE CONSOLE, HA!

Name: Anonymous 2007-03-17 16:09 ID:OlBFoWxb

OR USE A NONWINDOWS SYSTEM THAT DOESN'T CLOSE THE WINDOW ON PROGRAM EXIT

Name: Anonymous 2007-03-17 16:14 ID:tbIcxepU

int system(const char *); is standard sir.

Name: Ze Killer Of Poussin !SsWAPkwaM6 2007-03-17 16:18 ID:bpKL43Zg

>>46
LEARN TO READ MORON, I DIDN'T SAY system()  IS NOT STANDARD, I SAID  system("PAUSE") IS NOT, TRY YOUR FAGGOTRY ON ANOTHER SHIT THAN WINDOWS AND SEE THE EXTEND OF YOUR RETARDNESS.

Name: Anonymous 2007-03-17 16:26 ID:knrv8WBu

>>47
1. His pile of faggotry won't ever be turned into a real program.
2. Anything he compiles won't run on any platform that doesn't have `pause.'
3. Caps lock is cruse control for COBOL.
4. Remove the system call when compiling.

Name: Anonymous 2007-03-17 16:27 ID:BAPoB7OR

47 fails.

Name: Anonymous 2007-03-17 16:33 ID:tbIcxepU

>>47
TO MAKE MR."I CARE ABOUT MAC AND LINUX AND I LICK MR.TARBALLS' ASS" HAPPY I'LL CORRECT MY CODE.


#include <stdio.h>
int main ()/*here you didn't specify main return type and you put a semicolon at the end(WTF)*/
{//you forgot it
int player1[4];
int player2[4];
int i;
for(i=0;i<4;i++)
{
int number;
printf ("Enter Player 1 number:/n");
scanf ("%d", &number);
player1[i]=number;
}
printf ("Enter Player 2 number:\n");
for (i=0;i<4;i++)
{
int number;
printf ("Please insert a number:\n");
scanf ("%d", &number);
player2[i]=number;
}

for(i=0;i<4;i++)
{
  if (player1[i]==player2[i])
    puts("1");
  else
    puts("0");
}

printf("PRESS ENTER TO LEAVE THE PROGRAM AND EXTEND YOUR FAGGOTRY AND I HOPE YOU ENJOYED USING LINUX TO RUN THIS PROGRAM IF YOU USED IT");

getchar();//BOO

return 0;//you forgot to return 0
}//you forgot this too

Name: Ze Killer Of Poussin !SsWAPkwaM6 2007-03-17 16:39 ID:bpKL43Zg

>>48
YOU STILL DON'T UNDERSTAND, LET'S START FROM THE BEGINNING (AND IT SEEMS LIKE I DON'T SCREAM LOUDLY ENOUGH OR YOU'RE THE BIGGEST MORON I'VE EVER SEEN)).
YOUR FIRST MISTAKE IS TO TEACH HIM NON-ANSI C, BUT THE MOST DANGEROUS IS THAT YOU DON'T TELL HIM THIS IS NOT PART OF THE LANGUAGE. HE SHALL KNOW WHAT IS PART OF THE STANDARD C AND WHAT IS NOT, OR WILL HE RUN IN BIG TROUBLES. HOW MANY FUCKING TIMES ON PROGRAMMING BOARDS WE HAVE RETARDED STUDENT THAT COMES TO SAY "BWEE MY CODE DID WORK AT SCHOOL BUT DOESN'T WORK AT HOME HEEEELP !!!!1ONE". IF YOU WANT TO TEACH TO OTHERS, TEACH WELL OR DIE FAGGOT. AND YES I LOVE CAPS LOCK AND SHIT ON YOUR FACE, HA!

Name: Anonymous 2007-03-17 16:41 ID:tbIcxepU

IM NOT >>48 FUCKTARD

Name: Anonymous 2007-03-17 16:50 ID:bpKL43Zg

>>52
Ha ha, I like how easy it is to troll others here (I'm caps lock-man).
But anyway, I still think what I wrote (without the bad words, though), it's better to use only ANSI-C for beginners, I explained why, and also because it's so easy to shoot yourself in the head with this language, so we must try to not give them more bullets to shoot. It's not about "anyway he will run his crap only on windows", it's about not confuse beginners mind (experience here).
So, yes he can use system("PAUSE"); but he must knows what it implies and where it comes from. Like everything else in C, I must say.

Name: Anonymous 2007-03-17 17:20 ID:knrv8WBu

>>51
ANSI C is almost as gay as K&R C, real men use ISO C.

Name: Anonymous 2007-03-17 17:36 ID:bpKL43Zg

>>53
Ok, and just to show I'm not only a troll, here is my version (the only difference is that I use fgets() instead of scanf() and introducing error detection)
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>

#define MAX_LENGTH 5

int
main(void)
{
  char player1[MAX_LENGTH] = { 0 };
  char player2[MAX_LENGTH] = { 0 };
  int i;

  puts("Player 1 : enter your number or GTFO");
  fgets(player1, MAX_LENGTH + 1, stdin);
  for (i = 0; i < MAX_LENGTH - 1; i++)
    if (!isdigit(player1[i]))
    {
      puts("YOU'RE WELCOME TO ENTER NUMBER, FAGGOT");
      exit(EXIT_FAILURE);
    }

  puts("Player 2 : enter your number or GTFO");
  fgets(player2, MAX_LENGTH + 1, stdin);
  for (i = 0; i < MAX_LENGTH - 1; i++)
    if (!isdigit(player2[i]))
    {
      puts("YOU'RE WELCOME TO ENTER NUMBER, FAGGOT");
      exit(EXIT_FAILURE);
    }

  for (i = 0; i < MAX_LENGTH - 1; i++)
    if (player1[i] == player2[i])
      puts("1");
    else
      puts("0");

  puts
    ("THIS CODE WAS MADE BY ZE GREAT KILLER OF POUSSIN, ENJOY YOUR AIDS, HA!");
  return 0;
}

Maybe with mistakes and/or incomplete, but it works.

Name: Anonymous 2007-03-17 17:41 ID:bpKL43Zg

>>55
shit, it's MAX_LENGTH + 1 in the arrays declarations (for '\n' and '\0')

Name: Anonymous 2007-03-17 17:54 ID:Heaven

>>56
Enjoy your C!!!

Name: Anonymous 2007-03-17 18:14 ID:tbIcxepU

I added a pause at the end

#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>

#define MAX_LENGTH 5

void pause();

int
main(void)
{

  char player1[MAX_LENGTH] = { 0 };
  char player2[MAX_LENGTH] = { 0 };
  int i;
  atexit(&pause);

  puts("Player 1 : enter your numbers or GTFO");
  fgets(player1, MAX_LENGTH + 1, stdin);

  for (i = 0; i < MAX_LENGTH - 1; i++)
  {
    if (!isdigit(player1[i]))
    {
      puts("YOU'RE WELCOME TO ENTER NUMBER, FAGGOT");
      exit(EXIT_FAILURE);
    }
  }

  puts("Player 2 : enter your numbers or GTFO");
  fgets(player2, MAX_LENGTH + 1, stdin);
  for (i = 0; i < MAX_LENGTH - 1; i++)
  {
    if (!isdigit(player2[i]))
    {
      puts("YOU'RE WELCOME TO ENTER NUMBER, FAGGOT");
      exit(EXIT_FAILURE);
    }
  }

  for (i = 0; i < MAX_LENGTH - 1; i++)
  {
    if (player1[i] == player2[i])
      puts("1");
    else
      puts("0");
  }
  puts
    ("THIS CODE WAS MADE BY ZE GREAT KILLER OF POUSSIN, ENJOY YOUR AIDS, HA!");
  return EXIT_SUCCESS;
}

void pause()
{
puts("Press ENTER to continue.");
getchar();
}

Name: Anonymous 2007-03-17 18:33 ID:knrv8WBu

void pause()
{
system("pause");
}


Fixed.

Name: Anonymous 2007-03-17 23:00 ID:Xfs6kGv3

Open a fucking terminal, idiots.

Name: Anonymous 2007-03-18 1:47 ID:GM5AIKck

>>59
*captain picard*

Turbo C's IDE lets you view screen output by pressing Alt+F5. Should be a menu option for it as well.

Name: Anonymous 2007-03-18 1:54 ID:Kt3lB+6U

Ok screw this. Can anyone give me a simple functional C program that a noob can understand? Google fails me.

Name: Anonymous 2007-03-18 2:17 ID:BHUCQ5h1

int main(int argc, char* argv[]) {
printf("lol simple functional program\n");
return 0;
}

Name: Anonymous 2007-03-18 2:57 ID:GM5AIKck

What do you not understand? A functional sample C program isn't going to do jack shit unless you have some idea of what you need help with.

Name: Anonymous 2007-03-18 4:13 ID:1sFWNjzO

>>62
The program I gave IS simple. I made the effort to do it for anonyfag, if you don't make the effort to try to understand it by yourself (and asking what you don't understand) GO FUCK YOURSELF FUCKTARD. Stop programming and do knitting instead, you're wasting our time and yours.

Name: Anonymous 2007-03-18 4:26 ID:Kt3lB+6U

Sorry, I posted >>62 without looking at the 2nd page of the thread and thought it was hopeless. I'll try it out now, thanks.

Name: Anonymous 2007-03-18 4:28 ID:Kt3lB+6U

Ok I tried it out and it works, but I need to add more. Player 2 gets 10 tries to guess the correct series of numbers before losing the game. Also, i'd like to make proper error messages when invalid numbers are entered - not simply terminate the program.

Name: Anonymous 2007-03-18 4:30 ID:1sFWNjzO

>>66
Ok, one instant, you really thrilled me (btw, I'm >>55). Use >>58 version, he improved it for your convenience.

Name: Anonymous 2007-03-18 4:40 ID:1sFWNjzO

>>67
Try to do it yourself first, it's not the hardiest part. That's why  my programm behavior is shitty : its just exits when the user put a wrong number.
Help :
- make a function that read what the user enters and verify if it is 4 digits, if it's not, ask him again (protip : recursion, the function will call itself). If you have understood what I've done, you have just 2 lines of code to write for this.
- for the ten tries, easy too. Define an int that will count until ten. If the user fail, increment it, when it reaches ten, exit the program.
Anything's ok ?

Name: Anonymous 2007-03-18 6:31 ID:Kt3lB+6U

I gave it a shot and it's god awful.. i'll keep working on it. Got 33 errors to find. Anyone wanna show tips?

Name: Anonymous 2007-03-18 7:30 ID:huXMppok

#include <stdlib.h>
#include <stdio.h>

int main()
{
  int player1[4];
  int player2[4];
 
  int i;
 
  for(i=0;i<4;i++)
  {
  printf("Number %i ?", i+1);
  scanf("%i", &player1[i]);
  }
 
  system("clear");

  int mistake; 

  while(mistake!=0)
  {
  for(i=0;i<4;i++)
  {
  mistake=0;
  printf("Guess for number %i ?", i+1);
  scanf("%i", &player2[i]);
  }
 
  puts("Results:");
   
  for(i=0;i<4;i++)
  {
  if (player1[i]==player2[i])
    printf("1");
  else
    {
    printf("0");
    mistake++;
    }
  }
  puts("");
  if (mistake!=0)
  puts("Try again.");
  }
  puts("A winrar is you !");
  return 0;
}

Name: Anonymous 2007-03-18 7:31 ID:1sFWNjzO

>>70
>>55 again.
Ok, here is the input function, try to do the rest, I'll post the full code later :
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#define MAX_LENGTH 6

void player_input(char player[], const int n);
const int player_1 = 1;
const int player_2 = 2;

int main(void)
{
  char player1[MAX_LENGTH] = {0};
  char player2[MAX_LENGTH] = {0};
  int i;
 
  player_input(player1, player_1);
  player_input(player2, player_2);
 
  for (i = 0; i < MAX_LENGTH - 2; i++)
    if (player1[i] == player2[i])
      puts("1");
    else
      puts("0");
  puts("THIS CODE WAS MADE BY ZE GREAT KILLER OF POUSSIN, ENJOY YOUR AIDS, HA!"); 
  return EXIT_SUCCESS;
}

void player_input(char player[], const int n)
{
  int i;
 
  printf("player %d : enter numbers or GTFO\n", n);
  fgets(player, MAX_LENGTH, stdin);
  for (i = 0; i < MAX_LENGTH - 2; i++)
    if (!isdigit(player[i]))
      {
    puts("bad input, try again moron");
    player_input(player, n);
      }
}

Make the ask_player() function, with a #define MAX_TRIES 10 and  an int that will be compared to this value, while its inferior, ask the player, if it's 'y' or 'Y' return to the beginning of the program, else, exit. It's easy, 10 lines or code or something like that.

Name: Anonymous 2007-03-18 8:41 ID:Kt3lB+6U

>>71
It works, but it doesn't limit Player1 to enter a total of 4 digits.

Anyways, thanks for all the input everyone. I'm still working on understanding >>72

I only have a faint idea on what some of the lines do. I guess my professor was really incompetent for asking us to make a program when she didn't even teach us about these stuff.

Name: Anonymous 2007-03-18 8:44 ID:Kt3lB+6U

Another noob question (yet again), how do I make it so that the program won't exit instantly? I'm talking about >>72

Name: Anonymous 2007-03-18 9:59 ID:oC8aoiJc

>>74
Run it from the command line.

Name: Anonymous 2007-03-18 10:48 ID:Heaven

STOP HELPING THIS GUY.
He's obviously too stupid and unmotivated.

Name: Anonymous 2007-03-18 11:09 ID:Kt3lB+6U

>>76
Yeah, I gotta admit I WAS unmotivated.. but now i'll try to do it.

Name: Anonymous 2007-03-18 11:14 ID:Kt3lB+6U

But seriously, I don't even know what #include <ctype.h>
#include <stdlib.h> are for.. My teacher said #include <stdio.h> was to call the library for commands, but that's it. Can you blame me if i'm stupid on C?

Name: Anonymous 2007-03-18 11:18 ID:0IsP5Opg

>>78 Can you blame me if i'm stupid on C?
Yes. If you can't learn things on your own when your teachers suck, you are just generally stupid.

Name: Anonymous 2007-03-18 12:48 ID:huXMppok

Yeah. If you want to learn C that bad and your teacher sucks, just go buy a book on C and learn by yourself.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List