Email Address Validation

Mar 13, 2013 at 2:11am
hi guys, i am wondering how to tackle this problem, please help.

***the most important thing is
no string, array or break is allowed for this programmme.

for the entry i may first input in a format like:
name <email>
e.g. june <june@xxx.com>

Rules are :
1. contain only one @
2. no consective dots


The output should be look like
name <email>
1 ok
2 ok
3 ok
4 ok
5 ok

or

name <email> (failed case)
1 ok
3 ok

can someone give me some clues?Thanks!!
Last edited on Mar 16, 2013 at 8:10am
Mar 13, 2013 at 4:06am
If you cant use an array or string, then you need to calculate for each character:

This will print whatever you type in:
1
2
3
4
5
cout << "Please enter some things and then hit enter\n: ";

int ch;
while ((ch = cin.get()) != '\n')
  cout << ch;


So number 1:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
cout << "Please enter some things and then hit enter\n: ";

int ch;
int atCount = 0; 
while ((ch = cin.get()) != '\n')
{
  switch(ch)
  {
  case '@':  ++atCount;  break;
  
  // Add the other important character events here
  }
}

if (atCount == 1) cout << "1 ok\n";

[/code]
Last edited on Mar 13, 2013 at 4:07am
Mar 13, 2013 at 4:49am
He had better make use of an if...statement since the use of break is disallowed
Mar 13, 2013 at 6:34am
yes the three important things are no array no string and no break...
Mar 14, 2013 at 12:34pm
can anyone help me?
Mar 14, 2013 at 2:36pm
I think they just did, if that is not clear, ask a question. Post your code so we can give comments
Last edited on Mar 14, 2013 at 2:37pm
Mar 14, 2013 at 3:52pm
It says nothing about the use of continue;.

Use a for-loop, one iteration. When a 'rule' is broken continue; to restart the loop.
Topic archived. No new replies allowed.