debug codeblocks

why when i debug this code, the arrow debugger disappear after line 29 ?
the output should be "YES"
if the input is =>
1
ABCDS1234Y




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
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <sstream>

using namespace std;


int main() {
    /* Enter your code here. Read input from STDIN. Print output to STDOUT */
    int n;

    cin>>n;
    if(n>=1&&n<=10)
    {
         bool valide1,valide2,valide3;
         string s[n+1];
        for(int i=0;i<=n;i++)
        {
            getline(cin,s[i]);
        }
        for(int i=0;i<n;i++)
        {
            valide1=1,valide2=1,valide3=1;
            for(int j=0;j<5;j++)
            {
                if(!isalpha(s[i].at(j))||!isupper(s[i].at(j)))
                {
                    valide1=0;
                }
            }
            for(int j=5;j<9;j++)
            {
                if(!isdigit(s[i].at(j)))
                {
                    valide2=0;
                }
            }
            if(!isalpha(s[i].at(9)||!isupper(s[i].at(9))))
               {
                    valide3=0;
               }
            if(valide1==0||valide2==0||valide3==0)
            {
                cout<<"NO"<< endl;
            }
            else if(valide1==1&&valide2==1&&valide3==1)
            {
                cout<<"YES"<< endl;
            }
        }
    }
    return 0;
}




Last edited on
Since you haven't seen fit to tell us what debugger you're using, or what line your arrow has disappeared at, I don't think we're going to be able to solve your little puzzle.
To get this code to compile I had to switch off pedantic-errors.
Apparently line 19 is not ISO C++.

Anyway your program fails at line 29 because string s[0] is an empty string due to the perennial problem of using cin>> and then a getline().

cin>>n leaves a '\n' in the stream. getline places all chars in the stream before the '\n' into the string but there are no chars before the '\n' so the string is empty. getline then removes the '\n' from the stream. Now that the stream is empty the next getline will prompt the user for input.
Topic archived. No new replies allowed.