Looking for a bit of help

So my lab tells me to creating reportingMark
A string named reportingMark to contain two to four characters
I can't figure out how to limit a string to a certain amount of characters
Here is what I've tried so far
1
2
3
4
5
6
7
8
9
10
11
 cout << "Please input your AAR reporting mark" << endl;
        cin >> reportingMark;
    do
    {
        if (reportingMark.length() <2 || reportingMark.length() >4);
        {
            cout << "Invalid. Please try again."<< endl;
            cout << reportingMark.length();

        }
    }while (reportingMark.length() <=2 || reportingMark.length() >=4);

It isn't working when I try 2 character lengths. Any ideas?
The loop is fine, but you're not reading reportMark in the loop, so it becomes an infinite loop. You need something like:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
    cout << "Please input your AAR reporting mark" << endl;
    cin >> reportingMark;

    do
    {
        if (reportingMark.length() <2 || reportingMark.length() >4);
        {
            cout << "Invalid. Please try again."<< endl;
            cout << reportingMark.length();

            cin >> reportingMark;
        }
    }
    while (reportingMark.length() < 2 || reportingMark.length() > 4);

I removed the test for equality in the while.
Last edited on
In any instances with characters of length 1-4 it still prints invalid.
Yeah I'm not sure. I'm trying equality in the while and it still just prints as invalid.
Topic archived. No new replies allowed.