loop the menu automatically

the pattern for what you ask looks like this:

do
{
get user input
perform action(s) on user input if not the quit action (just do nothing for that)
//the above is often a switch statement, but it does not have to be.
}while(input is not quit option)
it goes around the menu options, which I will be honest, I don't know what the menu is in your code. Its just a wall of print statements to me.

I think, again roughly, you want:

do
cin choice
switch on choice
end of switch //does anything else go in here besides the switch?
while(choice != whatever to exit)

What that is doing is looping once no matter what, get the input, process it (again, ignore if if the choice is to quit) and then see if it needs to quit (while check). If its not the quit, it loops back and does it again...

You need to add the whole loop that jonnin mentioned.

To prompt until the user gives a valid value, I prefer to use the pattern:
1
2
3
4
5
6
7
8
while (true) {
    prompt_for_input;
    get_input;
    if (input is valid) {
        break;
    }
    say_that_input_is_invalid;
}


It's hard to get used to this pattern because most people don't like breaking out of the middle of a loop, but to me, this expresses the actual logic very clearly.

Once you have the input you need a switch statement:
1
2
3
4
5
6
7
8
9
10
11
switch(choice) {
case 1:
    do the code;
    break;
case 2:
    do the code;
    break;
case 3:
    do the code;
    break;
}

Case 3 just sets a variable to indicate that you're done with the loop.

Have you learned about arrays? What about functions? Either one of these would help shrink your code for case 1 dramatically.
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
//This program prints a mailing label with all necessary information
#include <iostream>
#include <fstream>
#include <iomanip>
#include <math.h>

using namespace std;

int
main()
{

    string name, address, state, city, checkdigit1, first1,
	second1, third1, fourth1, fifth1;
    int zipcode, mailing, choice;
    int first, second, third, fourth, fifth, sum = 0, checkdigit;
    const double POSTAGEL = 0.49, POSTAGEE = 0.98, POSTAGEP = 2.54;
    double postage, totalpostage;
    float total = 0.0, weight;
    bool done = false;
    
    const int letter = 1, envelope = 2, parcel = 3;
    const int single_mailing = 1, multiple_mailing = 2, quit = 3;

    cout << fixed << showpoint << setprecision(2);
    cout << "  Welcome to the Mailing Label Printing System" << endl;
    cout << " " << endl;
    cout << "1 - Single mailing" << endl;
    cout << "2 - Multiple mailing" << endl;
    cout << "3 -- Quit" << endl;
    cout << "Enter your choice: ";

    do {

	// prompt for a choice until they give one that's valid
	while (true) {
	    cin >> choice;

	    if (1 <= choice && choice <= 3) {
		break;
	    }
	    
	    cout << "****************************************" << endl;
	    cout << "The valid choices are 1 through 3." << endl;
	    cout << "1 - Single mailing" << endl;
	    cout << "2 - Multiple mailing" << endl;
	    cout << "3 -- Quit" << endl;
	    cout << "Enter your choice again: ";
	}


	switch (choice) {

	case 1:
	    //single mailing label
	    cin.clear();
	    cin.sync();
	    /*  cout << "Please enter your name: ";
		getline(cin, name);
		cout << "Please enter your address: ";
		getline(cin, address);
		cout << "Enter the city you live in: ";
		getline(cin, city);
		cout << "Enter the state you live in: ";
		cin >> state ; */
	    cout << "Enter the zipcode you live in: ";
	    cin >> zipcode;
	    cout << "Enter 1 for Letter 2 for Envelope 3 for Parcel: ";
	    cin >> mailing;
	    cout << "Weight of the item to be mailed: ";
	    cin >> weight;


	    //calculate the check digit
	    //Break the five digit zip code into individual digits
	    first = zipcode / 10000,
		second = zipcode / 1000 % 10, third = zipcode / 100 % 10;
	    fourth = zipcode / 10 % 10;
	    fifth = zipcode % 10;

	    //add up the five digit zip code
	    sum = first + second + third + fourth + fifth;

	    // calculate the checkdigit
	    checkdigit = sum % 10;
	    checkdigit = (10 - checkdigit);

	    // conditions

	    if (first == 0)
		first1 = "||:::";
	    else if (first == 1)
		first1 = ":::||";
	    else if (first == 2)
		first1 = "::|:|";
	    else if (first == 3)
		first1 = "::||:";
	    else if (first == 4)
		first1 = ":|::|";
	    else if (first == 5)
		first1 = ":|:|:";
	    else if (first == 6)
		first1 = ":||::";
	    else if (first == 7)
		first1 = "|:::|";
	    else if (first == 8)
		first1 = "|::|:";
	    else if (first == 9)
		first1 = "|:|::";

	    if (second == 0)
		second1 = "||:::";
	    else if (second == 1)
		second1 = ":::||";
	    else if (second == 2)
		second1 = "::|:|";
	    else if (second == 3)
		second1 = "::||:";
	    else if (second == 4)
		second1 = ":|::|";
	    else if (second == 5)
		second1 = ":|:|:";
	    else if (second == 6)
		second1 = ":||::";
	    else if (second == 7)
		second1 = "|:::|";
	    else if (second == 8)
		second1 = "|::|:";
	    else if (second == 9)
		second1 = "|:|::";

	    if (third == 0)
		third1 = "||:::";
	    else if (third == 1)
		third1 = ":::||";
	    else if (third == 2)
		third1 = "::|:|";
	    else if (third == 3)
		third1 = "::||:";
	    else if (third == 4)
		third1 = ":|::|";
	    else if (third == 5)
		third1 = ":|:|:";
	    else if (third == 6)
		third1 = ":||::";
	    else if (third == 7)
		third1 = "|:::|";
	    else if (third == 8)
		third1 = "|::|:";
	    else if (third == 9)
		third1 = "|:|::";

	    if (fourth == 0)
		fourth1 = "||:::";
	    else if (fourth == 1)
		fourth1 = ":::||";
	    else if (fourth == 2)
		fourth1 = "::|:|";
	    else if (fourth == 3)
		fourth1 = "::||:";
	    else if (fourth == 4)
		fourth1 = ":|::|";
	    else if (fourth == 5)
		fourth1 = ":|:|:";
	    else if (fourth == 6)
		fourth1 = ":||::";
	    else if (fourth == 7)
		fourth1 = "|:::|";
	    else if (fourth == 8)
		fourth1 = "|::|:";
	    else if (fourth == 9)
		fourth1 = "|:|::";

	    if (fifth == 0)
		fifth1 = "||:::";
	    else if (fifth == 1)
		fifth1 = ":::||";
	    else if (fifth == 2)
		fifth1 = "::|:|";
	    else if (fifth == 3)
		fifth1 = "::||:";
	    else if (fifth == 4)
		fifth1 = ":|::|";
	    else if (fifth == 5)
		fifth1 = ":|:|:";
	    else if (fifth == 6)
		fifth1 = ":||::";
	    else if (fifth == 7)
		fifth1 = "|:::|";
	    else if (fifth == 8)
		fifth1 = "|::|:";
	    else if (fifth == 9)
		fifth1 = "|:|::";

	    if (checkdigit == 0)
		checkdigit1 = "||:::";
	    else if (checkdigit == 1)
		checkdigit1 = ":::||";
	    else if (checkdigit == 2)
		checkdigit1 = "::|:|";
	    else if (checkdigit == 3)
		checkdigit1 = "::||:";
	    else if (checkdigit == 4)
		checkdigit1 = ":|::|";
	    else if (checkdigit == 5)
		checkdigit1 = ":|:|:";
	    else if (checkdigit == 6)
		checkdigit1 = ":||::";
	    else if (checkdigit == 7)
		checkdigit1 = "|:::|";
	    else if (checkdigit == 8)
		checkdigit1 = "|::|:";
	    else if (checkdigit == 9)
		checkdigit1 = "|:|::";



	    // Display the collected data.
	    cout << " " << endl;
	    cout << " " << endl;
	    cout << " " << endl;
	    cout << "*******************************$" << "" << postage << endl;
	    cout << "" << endl;
	    cout << "" << endl;
	    cout << name << endl;
	    cout << address << endl;
	    cout << city << " " << state << " " << zipcode << " " << endl;
	    cout << "|" << "" << first1 << "" << second1 << "" << third1 << "" <<
		fourth1 << "" << fifth1 << "" << checkdigit1 << "" << "|" << endl;
	    break;

	case 2:
	    cout << "Case 2 is not yet implemented\n";
	    break;
	    
	case 3:
	    done = true;
	    break;
	}
    } while (!done);
}


just a function would do wonders.

at the top of the code before main:

string domino(int checkdigit)
{
string result;
if (checkdigit == 0)
result= "||:::";
else if (checkdigit == 1)
result= ":::||";
else if (checkdigit == 2)
result= "::|:|";
else if (checkdigit == 3)
result= "::||:";
else if (checkdigit == 4)
result= ":|::|";
else if (checkdigit == 5)
result= ":|:|:";
else if (checkdigit == 6)
result= ":||::";
else if (checkdigit == 7)
result= "|:::|";
else if (checkdigit == 8)
result= "|::|:";
else if (checkdigit == 9)
result= "|:|::";
}



down in the code

fifth1 = domino(fifth);
checkdigit1 = domino(checkdigit);

etc..
Are you sure you haven't learned about functions and arrays? This is so much easier with them. Using Jonnin's names:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
const char *domino[10] = {
                          "||:::",
                          ":::||",
                          "::|:|",
                          "::||:",
                          ":|::|",
                          ":|:|:",
                          ":||::",
                          "|:::|",
                          "|::|:",
                          "|:|::"
};
...
fifth1 = domino[fifth];
checkdigit1 = domino[checkdigit];


If you really can't do it this way then here's a method without arrays:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
// Here are the 5 character codes for digits 0-9.  Note that this is
// one string, formatted for clarity using the fact that in C++, you
// can write "Hello " "world" to create the string "Hello world".
const char *code = ("||:::"
                    ":::||"
                    "::|:|"
                    "::||:"
                    ":|::|"
                    ":|:|:"
                    ":||::"
                    "|:::|"
                    "|::|:"
                    "|:|::");
...
                // Now set first1...checkdigit1 to the appropriate
                // 5-character sequence in the code string
                string first1(code + 5*first, 5);
                string second1(code + 5*second, 5);
                string third1(code + 5*third, 5);
                string fourth1(code + 5*fourth, 5);
                string fifth1(code + 5*fifth, 5);
                string checkdigit1(code + 5*checkdigit, 5);

Topic archived. No new replies allowed.