d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > 500 Fg For Easy Task! > Just Explain!
Add Reply New Topic New Poll
Member
Posts: 234
Joined: Jun 17 2012
Gold: 161.00
Apr 19 2016 02:21pm
Hello, ill just cut straight to the chase, im giving 500 fg for any1 that can give me a big paragraph explaining like a 5 year old what does this code do, I got this code from a website and my final exam was to make a code (chosing one of any of the following 4: online calculator, hangman, library management system and tic tac toe).

I chose the hangman 1 since i found it online but i never attended classes since im lazy.. Anyways.. the professor will evaluate if you "know" your code or not, so I need some1 to check out the code and explain it to me like a dummy so I can give a speech in front of the class and look like I did/know the code.

If you feel you can do a better code and simpler, go ahead and do it and post it (with detailed explanation) and ill give u all my 1,033 FG. (Can be any of those 4 on top).

PS: my class is coding in spanish but I can just switch the names to spanish if needed.
PSS: all my work is done in "codeblocks" which is C++ I think.

CODE:

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

#define N 12
char txt[9];
char datos[N][9]={
"anteojo","avioneta","zapallo","martir",
"espejo","anzuelo","heciano","tripode",
"insecto","agujero","carnada","cabeza"};

char dibuj[9][7]={
"____",
"| |",
"| |",
"|",
"|",
"|",
"|",
"|",
"----"
};

struct pst{
int pos;
char part[5];
}parts[7]={{3," O"},{4," /"},{4,"|"},
{4,"\\"},{5," |"},{6," /"},{6," \\"}};

int main(int argc, char *argv[])
{
int n,m,o,p,i,j,r,eq=0;char lc,tmp[10];

srand(time(NULL));
o=rand()%N;

m=strlen(datos[o]);p=m-2;

txt[0]=datos[o][0];txt[m-1]=datos[o][m-1];
for(n=1;n<m-1;n++)txt[n]='_';txt[m]=0;
printf("Ahorcatesss!!! Vr. 1.0\n\n");tmp[0]=0;
for(i=0;i<9;i++)printf("%s\n",dibuj);

do{

for(j=0;j<strlen(tmp);j++){
lc=tmp[j];r=p;
for(n=1;n<m-1;n++)
if(datos[o][n]==lc){
txt[n]=lc;datos[o][n]='_';p--;
}
if(r==p){
strcat(dibuj[parts[eq].pos],parts[eq].part);
eq++;
}
for(i=0;i<9;i++)printf("%s\n",dibuj);
}

if(eq>=7)break;

if(p>0){
printf("\nPalabra: %s - Ingrese 1 letra (* para terminar): ",txt);
scanf("%10s",&tmp);
}lc=tmp[0];
system("cls");
}while(lc!='*'&&p);

if(!p)printf("\nPalabra: %s - Ganaste cara de Naco!!!\n\n",txt);
else if(eq>=7)printf("\nJAJA!!! Loooooser!!!\n\n");
else printf("\nK c's Papá??? Recatate!!!\n\n");

system("PAUSE");

return 0;
}
Member
Posts: 234
Joined: Jun 17 2012
Gold: 161.00
Apr 19 2016 02:31pm
I forgot to put the requirements of the hangman, ill try my best to translate:

1: At the start of the program, it must show this:
a) script(sp?) line (1 per letter)
b) marker
c) letters left to guess
d) letters guessed

2: User must guess the word, you must put 1 letter of the alphabet per try

3: Each letter must be compared with the word, if its correct it must show in the screen in the right place

4: Each incorrect letter also must be shown separate to have a register

5: to guess the word the user must have 5 chances. If the user enters 5 wrong letters, the game must show Game over and the final score

6: For each letter guessed, the user will be given 10 points

7: if he guesses the word, it will show the next word to guess

8: the program must try to select randomly a word from a list of words

9: the graphic mode is not required, however it should have signs of logic and an elegant code

10: Take the register of the players (name and score) in a text file (.txt)

11: the list of words must be in a text archive per "theme" (utilize at least 2 different word themes)

That's it. I dont think the code in my previous post is correct 100% so im giving all my gold to whoever can make it right and explain it.

My due date is this thursday at 4 pm~
Member
Posts: 234
Joined: Jun 17 2012
Gold: 161.00
Apr 19 2016 02:42pm
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

#define N 12
char txt[9];
char data[N][9]={
"eyeglasses","airplane","zapato","jeans",
"mirror","fishing hook","elderly","tripod",
"insect","hole","bait","head"};

char drawing[9][7]={
"____",
"| |",
"| |",
"|",
"|",
"|",
"|",
"|",
"----"
};

struct pst{
int pos;
char part[5];
}parts[7]={{3," O"},{4," /"},{4,"|"},
{4,"\\"},{5," |"},{6," /"},{6," \\"}};

int main(int argc, char *argv[])
{
int n,m,o,p,i,j,r,eq=0;char lc,tmp[10];

srand(time(NULL));
o=rand()%N;

m=strlen(data[o]);p=m-2;

txt[0]=data[o][0];txt[m-1]=data[o][m-1];
for(n=1;n<m-1;n++)txt[n]='_';txt[m]=0;
printf("Hanged!! Vr. 1.0\n\n");tmp[0]=0;
for(i=0;i<9;i++)printf("%s\n",drawing);

do{

for(j=0;j<strlen(tmp);j++){
lc=tmp[j];r=p;
for(n=1;n<m-1;n++)
if(data[o][n]==lc){
txt[n]=lc;data[o][n]='_';p--;
}
if(r==p){
strcat(drawing[parts[eq].pos],parts[eq].part);
eq++;
}
for(i=0;i<9;i++)printf("%s\n",drawing);
}

if(eq>=7)break;

if(p>0){
printf("\nWord: %s - Input 1 letter (* to end): ",txt);
scanf("%10s",&tmp);
}lc=tmp[0];
system("cls");
}while(lc!='*'&&p);

if(!p)printf("\nWord: %s – You won!\n\n",txt);
else if(eq>=7)printf("\nYou Lost!\n\n");
else printf("\nNope n\n");

system("PAUSE");

return 0;
}


NOTEEEE: the last line of the code, the 1 that says: ***else printf("\nNope n\n");*** the NOPE part i dont know what was there, there was no spanish in there, it was gibberish, so maybe the one who explains the code can switch it to something more in place? idk.. either way, this is the rough spanish to english translation.
Member
Posts: 769
Joined: Apr 1 2016
Gold: 0.00
Apr 19 2016 03:25pm
pm'd, thanks
Member
Posts: 13,425
Joined: Sep 29 2007
Gold: 0.00
Warn: 20%
Apr 19 2016 04:57pm
I hope you fail.
Member
Posts: 234
Joined: Jun 17 2012
Gold: 161.00
Apr 19 2016 09:32pm
Topic closed! thanks SoSSoS.
Member
Posts: 769
Joined: Apr 1 2016
Gold: 0.00
Apr 20 2016 06:30am
Quote (J1zzmaster @ Apr 19 2016 11:32pm)
Topic closed! thanks SoSSoS.


Yw
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll