Loops and File Processing

Good day to you all here at cplusplus.com!
After some time of stumbling back here I decided to join since I'm currently enrolled in a beginners C++ class. Now I understand you don't give homework answers which I'm fine with, the homework is indeed the experience and the key to learning. With that being said I'm looking more for suggestions or possibly being pointed in the right way as I feel that I have the right idea but I'm uncertain how to possibly execute it. Anyway, onward.

At the current moment I've been assigned to make an application that takes up orders and then prints out the total cost from the customers via the menu.

1
2
3
4
5
6
7
8
9
cout << "Welcome to La-Fe! Our Menu:";
	cout << "\n C - Coffee ($1.29)";
	cout << "\n J - Juice ($1.50)";
	cout << "\n S - Soda ($1.00)";
	cout << "\n T - Tea ($1.39)";
	cout << "\n M - Manager Special ($2.99)";
	cout << "\n X - Done with Placing Order";
	cout << "\n What drink would you like? Select C, J, S, T, M (or X to finish with order)\n";
	cin  >> userOrder;


What I know:
There needs to be a loop of some sort at the end so that once the single selection is made it will print cout<<"Thank you. You have ordered (____) as your drink."

There's a sentinel involved, that being X.

The program writes out on a text file the orders, and somehow keeps track of it and reads it at the end while printing the drinks. How many of that particular drink was ordered and the total of those ordered drinks. It involves outputFile and inputFile.

It loops. Each time an order is placed it first writes in the userOrder and then prints out on the screen what the user ordered with the cout statement written above. and then loops to the beginning of the cout statements. At the end it somehow pulls the orders but that I can figure out at a later point, the meat of this is the loop.

What I'd like to know (Your suggestions):
Which loop should I use so that it repeats the process until the sentinel is chosen? This is where I'm stuck for the moment as I've considered a do while but I need multiple statements as I need one for each drink which makes me believe it's otherwise. The condition for example
(userOrder == 'C' || userOrder == 'c')
that being userOrder is using a blank char.

I've considered a switch statement within a loop but as far as I understand that won't work either. The only think I can think of is sticking an if/ else if statement in a loop but then I personally feel like that's over doing it of course it's possible.

In any case I've tried bouncing ideas ala rubber duck but I can't seem to nail how to go about it, the answer is on the tip of my tongue but I need a little push.

Anyway, kinda long, but thanks for your time and assistance! The entirety of this project is due in a week but I tend to get rolling once I know what I'm doing so I'll gladly keep the thread posted.
Last edited on
In pseudo code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14

Call the function to display your menu

Get the input from the user

Verify the input is valid:
    If it is valid,
        If it is the 'X'
            Handle it
        else
            print your output;
    else
         display an error


Remember when a while is more correct than a do-while and choose the appropriate one.

Topic archived. No new replies allowed.