Mail Order type application

Mar 18, 2018 at 8:12pm
I'm trying to do an application that allows the user to enter a 4-5 character string consisting of a number, two letters that determine the output, and then 1 or 2 more numbers. If it is not 4-5 characters it should display a error message and display an error message if the 2 and 3rd characters are not a correct delivery method. I think I have a solid base to it but I have various errors and parts I don't know how to do. I would really appreciate it if I could get some help.

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
  // Chapter 13 Ex. 26.cpp : Defines the entry point for the console application.
//

#include <string>;
#include <iostream>;
using namespace std;


int main()
{
	string mailcd = "";
	string deliverMethod = "";
	cout << "Enter a mail code(-1 to end): ";
	getline(cin, mailcd);

	while (mailcd != "-1")
	{
		if (mailcd.length == 5 || mailcd.length == 4)
		{
			if (mailcd[1] = "M" && mailcd[2] = "S")
			{
				deliverMethod = "Mail - Standard";
			}
			else if (mailcd[1] = "M" && mailcd[2] = "P")
			{
				deliverMethod = "Mail - Priority";
			}
			else if (mailcd[1] = "F" && mailcd[2] = "S")
			{
				deliverMethod = "FedEx - Standard";
			}
			else if (mailcd[1] = "F" && mailcd[2] = "O")
			{
				deliverMethod = "Fedex - Overnight";
			}
			else if (mailcd[1] = "U" && mailcd[2] = "P")
			{
				deliverMethod = "UPS";
			}
			else
			{
				"Enter a valid delivery method.";
			}
			cout << "Delivery method: " << deliverMethod << endl;
		}
	}
    return 0;
}

Mar 18, 2018 at 8:15pm
while (mailcd != "-1")

Where, in your while loop, can mailcd change? Why would this loop not loop forever?
Mar 18, 2018 at 8:34pm
I'm not sure, I've been trying to figure this program out for the past hour or so and i'm at a loss.
Mar 18, 2018 at 8:35pm
If you want a while loop to end, you need to change something inside the while loop to make the condition false.

https://www.tutorialspoint.com/cplusplus/cpp_while_loop.htm
Mar 18, 2018 at 9:44pm
The loop isn't my main problem the (mailcd[1] = "F" && mailcd[2] = "O") is getting errors and so is the rest of the else statements underneath the = "_".
Mar 18, 2018 at 9:46pm
= is not the same as ==
Mar 18, 2018 at 10:02pm
So I should be using ==?
Topic archived. No new replies allowed.