blob: 73de4a791a30f6ad6de36a20634cdb520f70b866 (
plain) (
blame)
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
|
// Tyler Taormina
// CST 116
// Lab 7
// Number 1
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
void GatherStrings();
void getString();
void ClearBuffer();
#define MAX 100
int main()
{
// program driver
GatherStrings();
return 0;
}
void GatherStrings()
{
// Ask user for input of a string. Let user decide after each
// input whether or not they will add another string. Once
// they choose to not input, all previously entered strings
// will be printed.
string usr_data;
string array[MAX];
int i = 0;
int limit = 0;
int flag = 1;
while (flag && limit < MAX)
{
cout << setw(10) << left << "Please Enter a string to store in our database: ";
getline (cin, usr_data);
array[limit] = usr_data;
limit += 1;
cout << "\n\nEnter [1] to add another string to the data base." << endl;
cout << "OR" << endl;
cout << "Enter [0] to stop and see all the entries we have so far: ";
cin >> flag;
ClearBuffer();
}
cout << "==================================================================\n";
cout << "This is what we have in our database so far..." << endl;
cout << "==================================================================\n";
while (i < limit)
{
cout << array[i] << endl;
i += 1;
}
}
void ClearBuffer()
{
// clears buffer after menu choice so as not to interfere with the following user inputs.
char c;
do {
c = getchar();
} while (c != '\n' && c != EOF);
}
|