Keep asking for user input - part two.

Original Problem:

Write a program that asks the user to order an ice cream treat. The user selects the type of ice cream, the sauce, and whether or not to add sprinkles. Use the screen shots below as a guide. Note that the user can answer the questions in any order and can change his/her mind. Also note that the "chocolate" may refer to either the ice cream or the sauce; assume the answer "chocolate" refers to sauce if the ice cream flavor has already been selected, otherwise assume it refers to the ice cream flavor.


I've finally figured out the majority of my program, but there is only one last problem. I can't for the life of me decide on how to fix the chocolate part. When you enter chocolate, it automatically assigns it to both the ice cream and sauce. Is there a way I can assign it to just the first question (ice cream) initially?

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
#include <iostream>
#include <string>
using namespace std;

int main() 
{

	string icecream = "", sauce = "", sprinkles = "", answer;


do
{
	if (icecream == "")
	cout << "Do you want chocolate, vanilla or twist?" << endl;

	if (sauce == "")
	cout << "Do you want hot fudge, chocolate or strawberry sauce?" << endl;

	if (sprinkles == "")
	cout << "Do you want sprinkles (yes/no)? " << endl;
		getline(cin, answer);

	if ((answer == "chocolate") || (answer == "vanilla") || (answer == "twist"))
		icecream = answer;

	if ((answer == "hot fudge") || (answer == "chocolate") || (answer == "strawberry"))
		sauce = answer;

	if ((answer == "no") || (answer== "yes"))
		sprinkles = answer;
		}

 while ((icecream == "") || (sauce == "") || (sprinkles == ""));

    if (sprinkles == "yes")
		{
    cout << "You ordered " << icecream << " ice cream with " << sauce << " sauce and sprinkles." << endl;
		 }
    else
        {
    cout << "You ordered " << icecream << " ice cream with " << sauce << " sauce without sprinkles." << endl;

		}

}

Hi xcrossmyheartx,
We must be taking the same online course through Penn State world campus.

I am having the same issue.
Did you figure it out?
I think the problem is looking for something like this (psuedocode):

print "What ice-cream do you want?"
get user input
//here you deal with the input, and assign it appropriately
//e.g.:
if answer == "chocolate"
if icecream.empty() icecream = answer
etc...

So you don't ever specifically prompt them for "What flavor" etc...

It still sounds kind of odd to me but that's what they assigned.
Topic archived. No new replies allowed.