Hi! i have problems with input validation, so here goes the problem :

Write a program that uses a structure to store the following data about a customer
account:
Name
Address
City, State, and ZIP
Telephone Number
Account Balance
Date of Last Payment
VideoNote
Solving the
Weather
Statistics
Problem
Review Questions and Exercises 647
The program should use an array of at least 20 structures. It should let the user enter
data into the array, change the contents of any element, and display all the data stored
in the array. The program should have a menu-driven user interface.
Input Validation:** When the data for a new account is entered, be sure the user enters
data for all the fields.** No negative account balances should be entered.

so here's my code :

#include <iostream>
#include <string>


using namespace std;

struct Customer
{
    string name;
    string adress;
    string city, state, ZIP;
    int telp;
    double accBal;
    string date;
};

void getdata(Customer[]);

int main()
{
    Customer bank[5];
    getdata(bank);

}

void getdata(Customer b[])
{
    for(int count = 0; count < 5; count++)
    {
        cout<<"enter name for person "<<count+1<<" = ";
        getline(cin, b[count].name);
        cout<<"enter adress for person "<<count+1<<" = ";
        getline(cin, b[count].adress);
        cout<<"enter city for person "<<count+1<<" = ";
        getline(cin, b[count].city);
        cout<<"enter state for person "<<count+1<<" = ";
        getline(cin, b[count].state);
        cout<<"enter ZIP for person "<<count+1<<" = ";
        getline(cin, b[count].ZIP);
        cout<<"enter telephone number for person "<<count+1<<" = ";
        cin>>b[count].telp;
        cout<<"enter account balance for person "<<count+1<<" = ";
        cin>>b[count].accBal;
        cout<<"enter date of last payment for person "<<count+1<<" = ";
        cin.ignore();
        getline(cin, b[count].date);
    }
}

the problem is i dont know how to make sure the user enters data for all fields
anyone can help me? :D

Edited 4 Years Ago by Sendy Hipo

Test each value entered. Make sure something was typed in. Are string.lengths greater than 0? Are numbers not 0?

This question has already been answered. Start a new discussion instead.