Input of String not working..

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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <ctype.h>
using namespace std;
int main()
{
    char str[25];
    cout<<"Enter your First name:"<<"(Lower case please)"<<"\n";
    gets(str);
    int i=0;
    if((str[i]=='a')&&( str[i+1]=='l')||(str[i]=='A')&&(str[i+1]=='L'))
    {cout<<"Welcome Back Agent Memphis "<<"\n";
     cout<<"Enter Your date of Birth and month to confirm your identity"<<"(Date/ Month-Enter Date first)"<<"\n";
     int a,b;
     cin>>a>>b;
     if(a==25&&b==03)
     {
         cout<<"Details Correct"<<"\n";
         cout<<"Step 1 of 3 Complete"<<"\n";
     }
    else
       {

        cout<<"You have entered incorrect details!"<<"\n";
        exit(EXIT_SUCCESS);
       }
    int c;
    cout<<"Enter the Last two digits of Your Phone number"<<"\n";
    cin>>c;
    if(c==66)
      {

        cout<<"Details Correct"<<"\n";
        cout<<"Step 2 of 3 Complete"<<"\n";
     }
     else
     {

        cout<<"You have entered incorrect details!";
        exit(EXIT_SUCCESS);
     }
    }

string email;
cout<<"Enter your email id:"<<"\n";
getline(cin,email);
return 0;

}


here's the output:
Enter your First name:(Lower case please)
alpha
Welcome Back Agent Memphis
Enter Your date of Birth and month to confirm your identity(Date/ Month-Enter Date first)
25
03
Details Correct
Step 1 of 3 Complete
Enter the Last two digits of Your Phone number
66
Details Correct
Step 2 of 3 Complete
Enter your email id:

Process returned 0 (0x0)   execution time : 12.444 s
Press any key to continue.


it does not input the email from the user.it directly goes to the return statement.please help. if you have better codes then please comment below. thankyou
Last edited on

This code:
getline(cin,email);
is reading '\n' - the end-of-line character that was left there.

https://mathbits.com/MathBits/CompSci/APstrings/APgetline.htm
i am sorry, i don't understand. can you tell me what set of codes i should use instead?
You can fix your immediate problem by, after every cin >> something, writing cin.ignore().

This is voodoo coding; writing magic code that you don't understand. This is not a good way to code and you should try not to.

Thank you so much. I got it.It works now. i actually understood that.
Topic archived. No new replies allowed.