Completed Parallel Arrays Flaws

This program uses parallel arrays to create a database, it's completed but it contains some logic flaws, if you can help I'd appreciate it.

Flaws:

1. Find function, given a product number, find the location of the product in the productnum array.

2. Add function, the program doesn't check the duplicated product #, and doesn't provide an exit for this functionality. Please pay attention to the type check.

3. Display function, when the database is empty, the function doesn't work correctly.

4. Print function, can't exit the print loop, also print function doesn't work the way it should be: it should print whatever is in the database and if nothing is there, just show empty database.

5. Update function, I can't check this function because after adding it never exits the adding mode to let me show what's in database first.

6. I want the user menu to loop, so they can select another option after each choice.
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
103
    
#include <iostream>
using namespace std;
    
    const int arraysize = 1000;
    double productnum[arraysize];
    double price[arraysize];
    int quantityonhand[arraysize];
    
    int findproduct (double productnum[], int siz, int found) {
        //cout << "Enter product number." << endl;
        for (int i = 0; i < siz; i++) {
            if (productnum[i] == found)
            return i;
        }
        return -1;
    }
    
    void addphone (double productnum[], double price[], int quantityonhand[], int num1) {
        int addc = 0;
        while (!(cin >> addc)) {
            string check;
            cin.clear();
            getline(cin,check);
            cout << "Invalid enter numeric value." << endl;
    
        for (int i = 0;i < num1; i++) {
            if ((productnum[i] || price[i] || quantityonhand[i])==0) {
                cout << "Stoping entries." << endl;
            } else {
            cout << "Product Number " <<  ": ";
            cin >> productnum[i];
            cout << "Price " << ": ";
            cin >> price[i];
            cout << "Quantity On Hand " << ": ";
            cin >> quantityonhand[i];
        }//end else
        }//end for
        }//end while
    }
    
    void updategame (double productnum[], double price[], int quantityonhand[], int prodt) {
        //cin >> prodt;
        cin >> prodt;
        for (int i = 0;i < prodt; i++) {
            cin >> price[i] >> quantityonhand[i];
        }
    
    }
    
    void displaygame (double productnum[], double price[], int quantityonhand[], int am) {
        //cin >> am;
        for (int i=0; i < am; i++) {
            cout << "Product: " << productnum[i] << endl;
            cout << "Price: " << price[i] << endl;
            cout << "Quantity on Hand: " << quantityonhand[i] << endl;
        }
    }
    
    void printdata (double *productnum, double *price, int *quantityonhand, int amp) {
        //cin >> am;
        for(int i = 0; i < amp; i++) {
            cout << "Product Number " << productnum[i] << "\t" << "Price " << price[i] << "\t\t" << "Quanitity on Hand " << quantityonhand[i] << endl;
        }
    }
    
    int main () {
        cout << "Welcome to The SmartPhone Database." << "\n" << "Please select an option." << endl;
        cout << "\n" << "***Menu***" << "\n1. Add Item" << "\n2. Update Item" << "\n3. Display Item" << "\n4. Print Database" << "\n5. Exit Program\n" << endl;
        int entry;
        cin >> entry;
        while (entry != 5) {
        switch (entry) {
            case 1:
                int num;
                cout << "How many phones would you like to enter?" << " \nEnter product number, price, quantity on hand after amount of phones." << endl;
                cin >> num;
                addphone(productnum, price, quantityonhand, num);
                break;
            case 2:
                int numup;
                cout << "Enter the product number to update the price and quantitiy on hand." << endl;
                cin >> numup;
                updategame(productnum, price, quantityonhand, numup);
                break;
            case 3:
                int numdis;
                cout << "Enter the array value to display the items." << endl;
                cin >> numdis;
                displaygame(productnum, price, quantityonhand, numdis);
                break;
            case 4:
                int nump;
                cout << "How many lines of the database should be printed?" << endl;
                cin >> nump;
                printdata(productnum, price, quantityonhand, nump);
                break;
            case 5:
                return 0;
                }
            }
        return 0;
    }
Look at your code:
1
2
3
4
5
6
int entry;
cin >> entry;
while (entry != 5)
  {
    // code that does not contain 'entry'
  }

How does the end condition change due to the looping?


You don't seem to record how many entries your database contains. Why would that piece of info help you?
Topic archived. No new replies allowed.