|
-
August 1st, 2007, 12:34 PM
#1
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;
}
-
August 1st, 2007, 02:17 PM
#2
Re: What goes for cin here?
That depends. Do you want an integer, character, string?
Viggy
-
August 1st, 2007, 02:21 PM
#3
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.
-
August 1st, 2007, 02:31 PM
#4
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
-
August 1st, 2007, 02:35 PM
#5
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
-
August 1st, 2007, 02:38 PM
#6
Re: What goes for cin here?
 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.
-
August 1st, 2007, 02:48 PM
#7
Re: What goes for cin here?
Ok, I got it thanks alot for your help.
-
August 1st, 2007, 03:45 PM
#8
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!
-
August 2nd, 2007, 09:37 PM
#9
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
-
August 2nd, 2007, 09:39 PM
#10
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
-
August 3rd, 2007, 12:31 PM
#11
Re: What goes for cin here?
This is not really WinAPI, thus: moved.
-
August 3rd, 2007, 02:08 PM
#12
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:
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.
-
August 3rd, 2007, 02:36 PM
#13
Re: What goes for cin here?
 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!
[code] "your code here" [/code]
-
August 3rd, 2007, 02:56 PM
#14
Re: What goes for cin here?
-
August 23rd, 2007, 10:16 PM
#15
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|