Input Verification

Hey there, I'm creating a menu that will allow a user to enter and display billing information they input into arrays. I'm attempting to create a function which will prompt the user to input information into each of the arrays.

I currently have the length set at 2 for testing purposes but each array should not be greater than 10.

I will be calling this from main, where I already have four arrays set to currently the size of 2.

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
'
void customerValidation(string customerName[],string boatName[],float contract[],float PTD[])
{
    
    
    
    //read in customer name
    for(int i =0; i < 2; i++)
    {
        cout<<"enter you first and last name"<<endl;
        getline(cin,customerName[i]);
        //if custName > 15
        //cannot be greter than
        
        cout<<"enter boat name"<<endl;
        getline(cin, boatName[i]);
        
        cout<<"Enter Contract Value\n";
        cin>>contract[i];
        cin.ignore();
        
        cout<<"Enter amount paid to date\n";
        cin>>PTD[i];
        cin.ignore();
        
        
        
    } 

MY QUESTION is, how would I validate the length of the strings input by the users in a way that the compiler won't scream at me for trying to compare a string to what's in the array position.

I do have another question that popped up in my head as I was typing this. How could I adjust it to where I enter info for just one user until the array reaches the size of 10. For an example, menu option 1 is to input custy info. Currently when selecting it, I have to enter info for each person until the array is full.
An example of how I'd like it to work,
I select option 1, enter what is needed for 1 customer and I should have the menu prompted again, instead of continuing to fill in the whole array.

I hope this makes sense, I'm still a noob willing to learn so I can provide more examples if needed. Mainly concerned with my first question. My second question is just for convenience hehehe.
Last edited on
1
2
if (customerName[i].length() > 15) 
  /* bail out */ ;
Much appreciated, that works smoothly
Topic archived. No new replies allowed.