Error on the Switch case 1

Currently facing an error on Case 1, where the if loop is totally ignored and from the previous interaction of user jumps to the next interaction without recognizing the if arguement.

Please help! Asking for a solution. To view the full code go to the URL: cpp.sh/9buy
It's too much code to fit in here.

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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
int main()
{

      char uname[20];
      char userpassword[20];
      char user2[20]; char password2[20];
      char name[20];
      char address[20];
      char tc[4];
      char twn[20];
      char cty[20];
      int phnumber;
      char dob[20];
      int a;
      char nationalityproof[20];
      int choice;
      int choice2;


      cout<<"Welcome to the Social Security Program. \n"<<flush
         <<"If you don't have an account enter the letter 'N' \n"<<flush
         <<"\n To begin. Please Login. \n"<<flush<<endl;

     User u(uname, userpassword);
     cout<<"Username: \n";
     cin.getline(uname,20);

     cout<<"Password: \n";
     cin.getline(userpassword,20);

        if (uname == "N" || uname == "n")
     {
         cout<<"Welcome Guest. \n Let's create your account \n To continue, follow the instructions below \n";
         cout<<"Please enter your new username \n"<<endl;
         cin.getline(user2, 20);
         cout<<endl;
         cout<<"Please enter your new password \n"<<endl;
         cin.getline(password2, 20);
         cout<<endl;
         cout<<"Please wait while your new profile is being created... \n"<<flush;
         u.Create_new_user(user2, password2);
         system("PAUSE");
         system("CLS");
     };


        u.Login();
        system("CLS");

         Database d("Luke", "49 Bishop St.", " ", "Belize City", 6629895, "June 1st, 1997", 20);
         d.showmenu();
         cin>>choice;
         while (choice != 4)
         {
            //d.print();
            //d.Agedetermination();
            Database d2(name, address, twn, cty, phnumber, dob, a);
            switch (choice)
            {
            case 1: //adding a new customer
            {


                cout<<"Please enter the customer's name \n";
                cin>>name;

                cout<<"Please enter the customer's address \n";
                cin>>address;


                cout<<"Does the customer live in a town or city? \n";
                cin>>tc;

                if (tc == "town" or tc == "Town" or tc == "TOWN")
                {
                    cout<<"Please enter the customer's town \n";
                    cin>>twn;

                }
                else if (tc == "city" || tc == "City" || tc == "CITY")
                {
                    cout<<"Please enter the customer's city \n";
                    cin>>cty;
                };

                cout<<"Please enter the customer's age \n";
                cin>>a;

                cout<<"Please enter the customer's phone number \n";
                cin>>phnumber;
                cout<<endl;
                cout<<"Please enter the customer's date of birth \n";
                cin.getline(dob, 20);
                cout<<endl;

                Database d2(name, address, twn, cty, phnumber, dob, a);
                d2.print();
                d2.Agedetermination();
                d2.showmenu();
                cin>>choice;
            break;
            }

Last edited on
If any of the data you're entering consists of more than a single word, the extraction operator (>>) is not appropriate for the task. Why are you using cin.getline in some places and not in others?

Also, if is not a loop, nor does it have arguments.
sometimes it captures the string the customer would enter it and save it in the variable, but if i use it in all cin, then it doesn't work but skips the entire thing

Any solutions per say you would see fit for this error?
sometimes it captures the string the customer would enter it and save it in the variable


When you switch to cin.getline you also run into the problem that it isn't appropriate for entering data to be stored as numbers, such as your phone number representation. But, that is more easily handled as a string anyway... I'm not sure why you're storing it in an int. Your choice variable, too, could be a string.

If you're mixing getline with extraction operations, then you're mixing formatted and unformatted input operations and those require care to use together since they don't handle whitespace in quite the same way. Easier to just use strings and getline.

You might want to peruse this stack overflow q&a:
https://stackoverflow.com/questions/21567291/why-does-stdgetline-skip-input-after-a-formatted-extraction
Last edited on
I made a slight change to the entire code. I've implemented the suggested solutions in the code, but no luck.

If someone could help me debug the entire code to maybe come up with the best solution, would be a lot of help.

here's the link to the entire code: cpp.sh/26ioi or cpp.sh/2ihg5

Last edited on
Topic archived. No new replies allowed.