Jump to content
deserty

problema joc C

Recommended Posts

Am luat codul de pe visual basic, vb, active server pages (ASP),java, c, c++, c__ , vbscript,active server pages, ASP, vbscript,SQL, database, informix, oracle, SQL Server,Perl, CGI,Delphi, PHP, LISP, Javascript,Free source code for the taking. Over five million lines o

Insa cand il compilez imi da eroarea Undefined symbol 'true' deoarece variabila true nu este definita.

Nu stiu c, insa v-as ruga sa imi spuneti ce valoare ar trebui sa ii dau ca sa nu-mi afecteze codul ?

Eu am incercat dandu-i valoarea 1 si a mers.


#include <String.h>
#include <Stdlib.h>
#include <Stdio.h>
#include <Time.h>

char State[50][255] = {"Alabama",
"Alaska",
"Arizona",
"Arkansas",
"California",
"Colorado",
"Connecticut",
"Delaware",
"Florida",
"Georgia",
"Hawaii",
"Idaho",
"Illinois",
"Indiana",
"Iowa",
"Kansas",
"Kentucky",
"Louisiana",
"Maine",
"Maryland",
"Massachusetts",
"Michigan",
"Minnesota",
"Mississippi",
"Missouri",
"Montana",
"Nebraska",
"Nevada",
"New Hampshire",
"New Jersey",
"New Mexico",
"New York",
"North Carolina",
"North Dakota",
"Ohio",
"Oklahoma",
"Oregon",
"Pennsylvania",
"Rhode Island",
"South Carolina",
"South Dakota",
"Tennessee",
"Texas",
"Utah",
"Vermont",
"Virginia",
"Washington",
"West Virginia",
"Wisconsin",
"Wyoming"};

char Capital[50][255] = {"Montgomery",
"Juneau",
"Phoenix",
"Little Rock",
"Sacramento",
"Denver",
"Hartford",
"Dover",
"Tallahassee",
"Atlanta",
"Honolulu",
"Boise",
"Springfield",
"Indianapolis",
"Des Moines",
"Topeka",
"Frankfort",
"Baton Rouge",
"Augusta",
"Annapolis",
"Boston",
"Lansing",
"St. Paul",
"Jackson",
"Jefferson City",
"Helena",
"Lincoln",
"Carson City",
"Concord",
"Trenton",
"Santa Fe",
"Albany",
"Raleigh",
"Bismarck",
"Columbus",
"Oklahoma City",
"Salem",
"Harrisburg",
"Providence",
"Columbia",
"Pierre",
"Nashville",
"Austin",
"Salt Lake City",
"Montpelier",
"Richmond",
"Olympia",
"Charleston",
"Madison",
"Cheyenne"};

int main()
{
srand(time(0));

int NumCorrect = 0;
int NumIncorrect = 0;
int true = 1;
while(true)
{
int RandNum = rand() % 49;

if(!strlen(State[RandNum]))
{
while(!strlen(State[RandNum]))
{
RandNum = rand() % 49;
}
}

char Answer[255];
char Buffer[255];

sprintf(Buffer, "What is the capital of %s?", State[RandNum]);
puts(Buffer);
gets(Answer);

if(!strcmp(Answer, Capital[RandNum]))
{
NumCorrect ++;

if(NumCorrect == 50)
{
puts("You guessed all 50 state capitals!\n"
"You win!!! (-:");

system("pause");

exit(EXIT_SUCCESS);
}

strcpy(State[RandNum], "");
strcpy(Capital[RandNum], "");
printf("%s, was correct! Excellent Job!\n", Answer);
}
else
{
NumIncorrect ++;

if(NumIncorrect == 3)
{
puts("You got three (3) answers incorrect.\n"
"You lose!!! )-:");

system("pause");

exit(EXIT_SUCCESS);
}

printf("%s, was incorrect. The correct answer was %s.\n", Answer, Capital[RandNum]);
}

printf("Your score is:\n"
"Correct : %i\n"
"Incorrect : %i\n\n", NumCorrect, NumIncorrect);

system("pause");
system("cls");
}

system("pause");

return(0);
}

Link to comment
Share on other sites

Ti-ai rezolvat problema

Nu exista o regula pentru a defini True sau False , pot fi variabile sau constante

Exemplu:


#include <stdio.h>
#define TRUE 0x1
#define FALSE 0x0

int main(void)
{
printf("TRUE = %d\n",TRUE);
printf("FALSE = %d\n",FALSE);
}

Edited by pyth0n3
Link to comment
Share on other sites

1.TRUE sau FALSE pot fi definite in C/C++ in Uppercase

2.true sau false pot fi definite in C/C++ in Lowercase

Au acelasi efect depinde doar de stilul in care este obijnuit programatorul sa scrie cod

Eu prefer sa scriu constantele in Uppercase si sa declar variabile in Lowercase

Daca totusi preferati sa scrieti cod in C dupa standard-ul C99 atunci urmatorul exemplu este echivalent cu exemplul facut mai sus dar nimeni nu va obliga sa definiti constantele in Lowercase sau Uppercase , denumirea e doar o conven?ie, iar pentru compilator e acelasi lucru


#define true 0x1
#define false 0x0

Valorile pot fi la randul lor folosite in mod alternativ in ambele libaje C/C++

Scrieti cod ,compilati-il si o sa va dati seama ca nu schimba nimic.

In C# lucrurile stau intrun mod divers unde orice valoare diversa de 0 e true

Edited by pyth0n3
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...