CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 15 of 15
  1. #1
    Join Date
    Aug 2007
    Posts
    7

    What goes for cin here?

    #include <iostream>
    #include <string>
    using namespace std;

    int main()
    {
    cout << "\tMike's Login\n";
    int security = 0;

    string username;
    cout << "\nUsername: ";
    cin >> username;

    string password;
    cout << "Password: ";
    cin >> password;


    if (username == "Mike" && password == "password")
    {
    cout << "\nWelcome Mike, Please Select a Choice Below";
    cout << "\n1-Choice1";
    cout << "\n2-Choice2";
    cout << "\n3-Choice3";
    cin >> ????????

    }

    if (!security)
    cout << "\nYour login failed.";

    return 0;
    }

  2. #2
    Join Date
    Feb 2002
    Posts
    4,640

    Re: What goes for cin here?

    That depends. Do you want an integer, character, string?

    Viggy

  3. #3
    Join Date
    Aug 2007
    Posts
    7

    Re: What goes for cin here?

    Well I'd like to have it where it asks for a choice and then the user inputs "1" for example then it says "You've selected 1" or something. So I guess one that allows the user to input one of the choices.

  4. #4
    Join Date
    Feb 2002
    Posts
    4,640

    Re: What goes for cin here?

    Just declare a new variable (be it "int", "char", "std::string") and put that new variable in place of the "?????"

    Viggy

  5. #5
    Join Date
    Aug 2007
    Posts
    7

    Re: What goes for cin here?

    So, me being an idiot and forgetting how to declare a variable, do you put #define char at the top of the file, if not could you please explain, Thanks

  6. #6
    Join Date
    Feb 2002
    Posts
    4,640

    Re: What goes for cin here?

    Quote Originally Posted by ComputerNub5
    Code:
    #include <iostream>
    #include <string>
    using namespace std;
    
    int main() 
    {
    	cout << "\tMike's Login\n";
    	int security = 0;  // This is a variable declaration
    
    	string username;   // This is a variable declaration
    	cout << "\nUsername: ";
    	cin >> username; 
    
            string password;  // This is a variable declaration
    	cout << "Password: ";
    	cin >> password; 
    
    
    	if (username == "Mike" && password == "password")
    	{
    		cout << "\nWelcome Mike, Please Select a Choice Below";
    		cout << "\n1-Choice1";
    		cout << "\n2-Choice2";
    		cout << "\n3-Choice3";
    		cin >>  ????????
    		
    	}
    
    	if (!security)
    		cout << "\nYour login failed.";
    
        return 0;
    }
    Vig.

  7. #7
    Join Date
    Aug 2007
    Posts
    7

    Re: What goes for cin here?

    Ok, I got it thanks alot for your help.

  8. #8
    Join Date
    Jun 2007
    Location
    MA-USA
    Posts
    247

    Re: What goes for cin here?

    When Extracting From The Stream Using 'cin', It Is My Practice To Dump The
    Result Into A 'char' Type Variable.

    For Example, We Are Looking To Accept An Integer From The User,
    The User Types The Letter V On Accident And Hits The Return Key.

    This Causes The Input Stream To Fail And Your Console Enters An
    Infinite Loop, Thus Rendering The Application Useless.

    If You Dump Everything Into 'char' Type Variables You Can Then Convert Them To Whatever Type You Expected, And The Stream Will Remain Safe.

    Happy Coding!

  9. #9
    Join Date
    Aug 2007
    Posts
    7

    Re: What goes for cin here?

    OK once again I've forgotten what to place in the question marked area:


    #include <iostream>
    #include <string>
    using namespace std;

    int main()
    {
    cout << "\tMike's Login\n";
    int security = 0;

    string username;
    cout << "\nUsername: ";
    cin >> username;

    string password;
    cout << "Password: ";
    cin >> password;


    if (username == "Mike" && password == "password")
    {
    string integer;
    cout << "\nWelcome Mike, Please Select a Choice Below";
    cout << "\n1-Choice1";
    cout << "\n2-Choice2";
    cout << "\n3-Choice3";
    cout << "\nChoice?";
    cin >> integer;
    security = 5;

    if(???? = 1 );
    {
    cout << "\nYou've chosen 1";
    }
    }




    if (!security)
    cout << "\nYour login failed.";

    return 0;
    }


    If anyone could help, it would be greatly appreciated

  10. #10
    Join Date
    Mar 2002
    Location
    St. Petersburg, Florida, USA
    Posts
    12,125

    Re: What goes for cin here?

    If you showed the least bit of effort by using code tags, people would be more inclined to help.
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009,2010
    In theory, there is no difference between theory and practice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

  11. #11
    Join Date
    Mar 2004
    Location
    (Upper-) Austria
    Posts
    2,899

    Re: What goes for cin here?

    This is not really WinAPI, thus: moved.
    I am not offering technical guidiance via email or IM
    Come on share your photo with us! CG members photo album!
    Use the Code Tags!

  12. #12
    Join Date
    Aug 2007
    Posts
    4

    Re: What goes for cin here?

    Your if statement says:
    Code:
    if(???? = 1 );
    {
    cout << "\nYou've chosen 1";
    }
    First of all, drop the semi-colon at the end of your first line, that's causing your if statement to cease existence beyond that point, not good.

    Now take a good look at the parameters in your if statement:

    Code:
    ???? = 1;
    It's easy to confuse the assignment operator (=) to the equal to operator (==).

    Looks like you did declare a variable to accept the users input, now just plug it all in.
    Last edited by slickshoes; August 3rd, 2007 at 02:12 PM.

  13. #13
    Join Date
    Jun 2007
    Location
    United States
    Posts
    275

    Re: What goes for cin here?

    Quote Originally Posted by ComputerNub5
    OK once again I've forgotten what to place in the question marked area:

    if(???? = 1 );
    {
    cout << "\nYou've chosen 1";
    }

    The ???? should be what the cin saved the data to, which is "integer". and change the things slickshoes said, so it would look like

    Code:
            
            if( integer == 1 )
            {
                     cout << "\nYou've chosen 1";
            }
    Last edited by bovinedragon; August 3rd, 2007 at 02:38 PM.
    Don't forget to rate my post if I was helpful!

    Use code tags when posting code!
    &#091;code] "your code here" [/code]

  14. #14
    Join Date
    Aug 2007
    Posts
    7

    Re: What goes for cin here?

    ok thx alot

  15. #15
    Join Date
    Aug 2007
    Posts
    7

    Re: What goes for cin here?

    ok, to go along with what this whole project is, I just wondered. Is it possible to have a situation where it gives the user 1,2,3 for choices, and if the user chooses 1 for example it loads another application. If so, does anyone know the format, Thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured