Newbe help

This is a discussion on Newbe help within the C++ Programming forums, part of the General Programming Boards category; Hi, Im new to c++ and today, when i tryed to make "login program" i ran inti problem. Is it ...

  1. #1
    Registered User
    Join Date
    Aug 2004
    Posts
    11

    Newbe help

    Hi,
    Im new to c++ and today, when i tryed to make "login program" i ran inti problem. Is it possable to use character variables at if/else statements at all? I mean
    Code:
    if(username==user)
    {
    cout <<"Username verifyed, insert the password";
    cin>>password;
    }
    else
    {
    cout<<"Wrong username, try again!";
    cin>>username;
    }
    I keep getting error, that there is something wrong with the first if statement. I am using dev c++ compliler, i hope someone here is willing to help newbe like me. It also didnt accept if i compared character variable username to string, what takes information from text file. It worked all fine, when password and username were boath ONLY numbers.
    Regards,
    Kitu.
    Last edited by Kitu; 08-01-2004 at 03:10 AM.

  2. #2
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    For a start off "=" is an assignment operator....you use "==" to test if they are the same...also username==username is nonsence how can you be checking if something is itself?

  3. #3
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,801
    Code:
    if(username=username)//You are assigning username to username
    should be.
    Code:
    if(username==username)//this one your comparing
    Remeber "=" means assignment
    and "==" means comprason
    Woop?

  4. #4
    Registered User
    Join Date
    Aug 2004
    Posts
    11
    Quote Originally Posted by Fordy
    For a start off "=" is an assignment operator....you use "==" to test if they are the same...also username==username is nonsence how can you be checking if something is itself?
    Ya, im sorry, i didnt "copy-paste" te code, as it is at other computer, i just typed it in...At original i had there == and password word there was not password, i just typed it in here as an example without thinking. I will repear the example code, sorry for that mistake...

  5. #5
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    Soething a little closer to your needs;

    Code:
    #include <iostream>
    #include <string>
    
    
    int main()
    {
    	std::string username;
    	std::string acceptedusername("jimbob");
    
    	std::cout << "Enter Username" << std::endl;
    	std::cin >> username;
    
    	if(acceptedusername == username)
    	{
    		std::cout << "Username verifyed, insert the password";
    	}
    	else
    	{
    		std::cout<< "Wrong username, try again!";
    	}
    }

  6. #6
    Registered User
    Join Date
    Jul 2004
    Posts
    91
    why do you have std:: everywhere??
    is that hte same as not having std:: everywhere and having 'using namespace std' at hte top ?

  7. #7
    Registered User
    Join Date
    Aug 2004
    Posts
    11
    Fordy, thanx, got it now

  8. #8
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    Quote Originally Posted by paperbox005
    why do you have std:: everywhere??
    is that hte same as not having std:: everywhere and having 'using namespace std' at hte top ?
    Yeah...I never use the "using namespace..." thing

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Newbe question
    By RaisinToe in forum Game Programming
    Replies: 15
    Last Post: 01-28-2009, 05:01 PM
  2. Newbe request
    By Rokemet in forum C++ Programming
    Replies: 14
    Last Post: 09-20-2007, 11:41 PM
  3. newbe needs some help
    By Dr Spud in forum C Programming
    Replies: 18
    Last Post: 11-24-2005, 12:47 AM
  4. Please help (newbe post)
    By Dmax in forum C++ Programming
    Replies: 4
    Last Post: 02-17-2005, 08:52 PM
  5. WNDCLASSEX vs. WNDCLASS (Newbe) ???
    By niklaskr in forum Windows Programming
    Replies: 3
    Last Post: 06-19-2002, 09:44 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21