Thread: Having Problems with char equaling another char

  1. #1
    Registered User
    Join Date
    Apr 2002
    Posts
    16

    Post Having Problems with char equaling another char

    I am trying to make a program.. where yo guess a word ..lets say magic. and the program will reconize the word and print it up on a chart.

    i've tried everything i can think of and its probably a really simple answer but the answer to this problem will be greatly appreciated.

    I'm Using Microsoft Visual C++ 6.0.

    CODE: ______________________________________________


    if (quest==1)
    {
    gotoxy(40,8);
    cout<< "Guess the Word : "<<endl;
    while (ans1==false)
    {
    gotoxy(40,9);
    cout<<" "<<endl;
    gotoxy(40,9);
    cin>>guess;

    if (guess == answer[1])
    {
    gotoxy(1,1);
    cout<<"M"<<endl;
    gotoxy(3,1);
    cout<<"a"<<endl;
    gotoxy(5,1);
    cout<<"g"<<endl;
    gotoxy(7,1);
    cout<<"i"<<endl;
    gotoxy(9,1);
    cout<<"c"<<endl;

    ans1=true;
    }
    Microsoft Visual C++ 6.0

  2. #2
    I have that problem too.

  3. #3
    Registered User
    Join Date
    Mar 2002
    Posts
    125
    It would be practical if you'd add what kind of variables thse are. I'm guessing now that both guess and answer[1] are strings (character array)?
    You'll have to use the strcmp function from String.h. It's like this:
    if (strcmp(guess, answer[1])==0)
    {Guess correct!}

  4. #4
    Registered User
    Join Date
    Apr 2002
    Posts
    16
    This works thanks man!
    Microsoft Visual C++ 6.0

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. convering char to int problems
    By ominub in forum C Programming
    Replies: 5
    Last Post: 04-01-2009, 12:02 PM
  2. Replies: 7
    Last Post: 06-16-2006, 09:23 PM
  3. comparing fields in a text file
    By darfader in forum C Programming
    Replies: 9
    Last Post: 08-22-2003, 08:21 AM
  4. AnsiString versus char *
    By Zahl in forum C++ Programming
    Replies: 35
    Last Post: 10-16-2002, 08:38 PM
  5. errors in class(urgent )
    By ayesha in forum C++ Programming
    Replies: 1
    Last Post: 11-10-2001, 10:14 PM