Mar 10, 2012 at 3:18am UTC
im doing this log-in system..
how can possibly username variable has contains many value?
Mar 10, 2012 at 3:32am UTC
Im not sure I understand
How can a char username; contain many values?
Mar 10, 2012 at 3:56am UTC
User name can be inputted then validation would need to gathered. The getLine(cin, myString)
function can populate the string with a full name.
Mar 10, 2012 at 7:17am UTC
what im trying to do is..
username: me
would you like to add username? (y-yes): y
add username:
username: <new username>
now you have 2 username.
Mar 10, 2012 at 12:55pm UTC
Yep, make an array of strings.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
int main()
{
string username;
string storedNames[100];
int NumNames = 0;
while (true )
{
cout << "username: " ;
getline(cin,username);
bool exists = false ;
for (int i = 0; i < storedNames.size(); i++)
if (storedNames[i] == username)
exists == true ;
if (!exists)
{
char test;
cout << "would you like to add this username? (y/n): " ;
cin >> test;
if (test == y)
storedNames[NumNames++] = username;
}
else
cout << "You are logged in" << endl;
cout << "There are " << NumNames << " usernames" << endl;
}
}
Last edited on Mar 10, 2012 at 12:59pm UTC
Mar 10, 2012 at 2:58pm UTC
@magadavixt
What's there to help with? They've already given you all the information you need.
Mar 11, 2012 at 4:25pm UTC
Make sure to add this line to your file:
#include <string>
Mar 11, 2012 at 4:31pm UTC
error C2228: left of '.size' must have class/struct/union type
still got this error