Share your repls and programming experiences

← Back to all posts
Help
AbigailBurstein (0)

Write a program, containing 3 functions that will ask the user for his or her email address and print out the
following:
● The user's name or ID
● The user's character site type. Display the specific name for all 3-character site types.

I am at lost!

Commentshotnewtop
mwilki7 (993)

cout << "Your user Id is :" << ID;
ID was never declared anywhere

e_mail.IndexOf('@');
Strings in C++ don't have an 'IndexOf' function. In this case, you'd use find()

For example:

string test = "test";
int test_index = test.find('s');
cout << "'test' index of 's': " << test[test_index] << endl;

string domain = e_mail.Substring(indexOfAt + 1);
C++ uses 'substr' as the function name for substring.
You may have noticed the naming convention for C++ libraries is lowercase
('find' instead of 'Find', 'substr' instead of 'Substr' etc...).

AbigailBurstein (0)

How do I get it to print out the In general, the part before the name or ID of a particular user, and the part after the @ specifies the site at which the user is [email protected]

mwilki7 (993)

@AbigailBurstein
You can use find() to search for the '@' and that will give you the index of that symbol. Then use that index to print everything before it or after it.

For example:

string email = "[email protected]"
int at_index = email.find("@");

cout << "Before @: " << email.substr(0, at_index) << endl;
cout << "After  @: " << email.substr(at_index + 1, email.length() - 1) << endl;

you may need to add or subtract 1 to at_index in the substr function, I don't know if substr is "up to index" or "up to and including index".

DynamicSquid (1967)

Read the error messages

DynamicSquid (1967)

@AbigailBurstein

  1. main.cpp:74:45

main.cpp is the file name. That means the error in the in that file, not another one.

  1. main.cpp:74:45

74 is the line number. Ignore the 45. Just pay attention to the first number.

  1. error: use of undeclared identifier ID

So in the main.cpp file on line 74, ID is undeclared. That means the compiler doesn't know what it is.

  1. Also, use NULL instead of nullptr.