Re: What goes for cin here?
That depends. Do you want an integer, character, string?
Viggy
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.
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
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
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.
Re: What goes for cin here?
Ok, I got it thanks alot for your help.
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!
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
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.
Re: What goes for cin here?
This is not really WinAPI, thus: moved.
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.
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";
}
Re: What goes for cin here?
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