Thread: Newbie needing help with basic code!

  1. #1
    Registered User
    Join Date
    Nov 2007
    Posts
    3

    Exclamation Newbie needing help with basic code!

    Hi im new to the world of coding! Ive started out by reading some of the lessons on this site. They have been very helpful! I have started by trying a 'test' program. The program i am tryin to build is a basic username and password program (Sort of like a guessing game!)

    Im having many problems with the code!

    The code is
    Code:
    #include <iostream>
    
    using namespace std;
    
    int main()
    {
       char a;
       cout<<"Please enter username: ";
       cin>> a;
       cin.ignore();
       if ( a == "TeZ" ){
       cout<<"Password: ";
       cin.get();
     }
     
    }
    It will not compile at all! When i try to compile the program the compiler (Dev-C++) says 'ISO C++ forbids comparison between pointer and integer'

    Thanks in advance TeZ258

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    A char holds only a single character. You want a string, which holds 0 or more characters. Add a #include <string> and make the variable a string instead of a char.

  3. #3
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    a char is one character. use a string.
    Code:
    #include <iostream>
    #include <string>
    
    using namespace std;
    
    int main()
    {
       std::string a;
       cout<<"Please enter username: ";
       cin>> a;
       cin.ignore();
       if ( a == "TeZ" ){
       cout<<"Password: ";
       cin.get();
     }
     
    }

  4. #4
    Registered User
    Join Date
    Nov 2007
    Posts
    3
    Thanks i will try that and reply back on this thread

  5. #5
    Registered User
    Join Date
    Nov 2007
    Posts
    3
    Hey it works! Thank you loads guys!!!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Basic Win32 Service Control Code
    By The Dog in forum Windows Programming
    Replies: 4
    Last Post: 09-08-2006, 01:00 AM
  2. Replies: 18
    Last Post: 11-04-2005, 02:41 PM
  3. Winsock client code help.... very basic.
    By Jay_Tech in forum Windows Programming
    Replies: 7
    Last Post: 10-18-2002, 06:27 AM
  4. << !! Posting Code? Read this First !! >>
    By biosx in forum C++ Programming
    Replies: 1
    Last Post: 03-20-2002, 12:51 PM
  5. Newbie Source Code question. Hlp Plz?
    By BOOGIEMAN in forum Game Programming
    Replies: 4
    Last Post: 12-14-2001, 04:30 AM