I am having trouble with this program which was solved before, but I am still having an issue with the final code. Here is the assignment prompt:

Write a program that asks the user to order an ice cream treat. The user selects the type of ice cream, the type of sauce, and whether or not to add sprinkles. NOTE: "chocolate" may refer to either the ice cream or the sauce; assume it refers to the ice cream if an ice cream flavor has not yet been selected.

I have also attached pictures of what it should look like.

My problem is that when I run the program, and then I say "yes" or "no", trying to answer the sprinkles question, it ignores my response and still repeats all three questions, despite me having answered the sprinkles question. How can I alleviate this? I could really use the help...Thank you very much in advance for anyone that helps me.

Here is my code so far:

int main()
{
  string flavor, topping, sprinkles, choice;
  int terminate = 0;

  while( sprinkles == "")
	{
		if (terminate++ > 30)
		{
			break;
		}

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

		if( topping == "")
		{
			cout << "Hot fudge, chocolate or strawberry sauce?" << endl;
		}

		if( sprinkles == "")
		{
			cout << "Do you want sprinkles (yes/no)?" << endl;
		}
		
		getline(cin, choice);
		
		if( sprinkles == "" && topping != "" && flavor != "")
		{
			if( choice == "yes" || choice =="no" )
			{
				sprinkles = choice;
			}
		}

		if( sprinkles == "" && topping == "" && flavor != "")
		{
			if( choice == "hot fudge" || choice == "chocolate" || choice == "strawberry" )
			{
				topping = choice;
			}
		}


		if( sprinkles == "" && topping == "" && flavor == "")
		{
			if( choice == "chocolate" || choice == "vanilla" || choice == "twist" )
			{
				flavor = choice;
			}
		}

	}

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

  else
  {
	  cout << "You ordered " << flavor << " ice cream with " << topping << " sauce without sprinkles." << endl;
  }

}

I am having trouble with this program which was solved before, but I am still having an issue with the final code. Here is the assignment prompt:

Write a program that asks the user to order an ice cream treat. The user selects the type of ice cream, the type of sauce, and whether or not to add sprinkles. NOTE: "chocolate" may refer to either the ice cream or the sauce; assume it refers to the ice cream if an ice cream flavor has not yet been selected.

I have also attached pictures of what it should look like.

My problem is that when I run the program, and then I say "yes" or "no", trying to answer the sprinkles question, it ignores my response and still repeats all three questions, despite me having answered the sprinkles question. How can I alleviate this? I could really use the help...Thank you very much in advance for anyone that helps me.

Here is my code so far:

int main()
{
  string flavor, topping, sprinkles, choice;
  int terminate = 0;

  while( sprinkles == "")
	{
		if (terminate++ > 30)
		{
			break;
		}

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

		if( topping == "")
		{
			cout << "Hot fudge, chocolate or strawberry sauce?" << endl;
		}

		if( sprinkles == "")
		{
			cout << "Do you want sprinkles (yes/no)?" << endl;
		}
		
		getline(cin, choice);
		
		if( sprinkles == "" && topping != "" && flavor != "")
		{
			if( choice == "yes" || choice =="no" )
			{
				sprinkles = choice;
			}
		}

		if( sprinkles == "" && topping == "" && flavor != "")
		{
			if( choice == "hot fudge" || choice == "chocolate" || choice == "strawberry" )
			{
				topping = choice;
			}
		}


		if( sprinkles == "" && topping == "" && flavor == "")
		{
			if( choice == "chocolate" || choice == "vanilla" || choice == "twist" )
			{
				flavor = choice;
			}
		}

	}

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

  else
  {
	  cout << "You ordered " << flavor << " ice cream with " << topping << " sauce without sprinkles." << endl;
  }

}

You ask three questions right of the bat and don't stop for an answer:

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

		if( topping == "")
		{
			cout << "Hot fudge, chocolate or strawberry sauce?" << endl;
		}

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

Which of the three questions is the user answering here with the getline line? I'd have the code where the user enters input be directly after the cout prompt.

maybe you need to rearrange the program so that it does this

Do you want chocolate, vanilla or twist?
chocolate
hot fudge, chocolate or strawberry sauce?
hot fudge
Do you want sprinkles (yes/no)?
no
You ordered chocolate ice cream with hot fudge sauce without sprinkles.
Press any key to continue . . .

[edit]Same as ^^^ suggested :) [/edit]

The assignment states that you need to ask all three questions right off the bat, continually ask the questions until one of the correct responses is given, when a correct response is given the program checks to see what questions was answered, then takes that questions away and asks the remaining questions again. i know that's a bit confusing, it was to me at first, but here is an example (each >> is user input):

Do you want vanilla, chocolate, or twist?
Hot fudge, chocolate, or strawberry sauce?
Do you want sprinkles (yes/no)?
>>Hello

Do you want vanilla, chocolate, or twist?
Hot fudge, chocolate, or strawberry sauce?
Do you want sprinkles (yes/no)?
>>vanilla

Hot fudge, chocolate, or strawberry sauce?
Do you want sprinkles (yes/no)?
>>hello

Hot fudge, chocolate, or strawberry sauce?
Do you want sprinkles (yes/no)?
>>strawberry

Do you want sprinkles (yes/no)?
>>yes

You chose vanilla ice cream with strawberry sauce and. sprinkles.

As you can see, the program will eliminate questions already answered, and continue to ask until one of the responses is given.

My problem is that with my current code, the program will not stop asking the sprinkles question even if it already answered and only if it is the last questions answered, so it looks like this:

Do you want vanilla, chocolate, or twist?
Hot fudge, chocolate, or strawberry sauce?
Do you want sprinkles (yes/no)?
>>yes

Do you want vanilla, chocolate, or twist?
Hot fudge, chocolate, or strawberry sauce?
Do you want sprinkles (yes/no)?
>>yes

Do you want vanilla, chocolate, or twist?
Hot fudge, chocolate, or strawberry sauce?
Do you want sprinkles (yes/no)?
etc......

What makes this assignment even more boggling is that I can't simply have the questions asked up front, because there are TWO "chocolate" responses, one for ice cream and one for the sauce. Since the program HAS to ask all the questions up front, I needed to figure out a way to tell the program that the first "chocolate" input by the user is for the ice cream ONLY and not for the sauce. When the user inputs "chocolate" again, it is for the sauce.

Here is a link to the same assignment that was asked before on this forum, but did not answer my questions despite it being checked as "solved":

http://www.daniweb.com/forums/thread150790.html

if( sprinkles == "" && topping != "" && flavor != "")
		{
			if( choice == "yes" || choice =="no" )
			{
				sprinkles = choice;
			}
		}

Look at your if statement. Is this what you want? Will it pass the if test if all three variables are empty strings?

I am having trouble with this program which was solved before, but I am still having an issue with the final code. Here is the assignment prompt:

Write a program that asks the user to order an ice cream treat. The user selects the type of ice cream, the type of sauce, and whether or not to add sprinkles. NOTE: "chocolate" may refer to either the ice cream or the sauce; assume it refers to the ice cream if an ice cream flavor has not yet been selected.

I have also attached pictures of what it should look like.

My problem is that when I run the program, and then I say "yes" or "no", trying to answer the sprinkles question, it ignores my response and still repeats all three questions, despite me having answered the sprinkles question. How can I alleviate this? I could really use the help...Thank you very much in advance for anyone that helps me.

Here is my code so far:

int main()
{
  string flavor, topping, sprinkles, choice;
  int terminate = 0;

  while( sprinkles == "")
	{
		if (terminate++ > 30)
		{
			break;
		}

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

		if( topping == "")
		{
			cout << "Hot fudge, chocolate or strawberry sauce?" << endl;
		}

		if( sprinkles == "")
		{
			cout << "Do you want sprinkles (yes/no)?" << endl;
		}
		
		getline(cin, choice);
		
		if( sprinkles == "" && topping != "" && flavor != "")
		{
			if( choice == "yes" || choice =="no" )
			{
				sprinkles = choice;
			}
		}

		if( sprinkles == "" && topping == "" && flavor != "")
		{
			if( choice == "hot fudge" || choice == "chocolate" || choice == "strawberry" )
			{
				topping = choice;
			}
		}


		if( sprinkles == "" && topping == "" && flavor == "")
		{
			if( choice == "chocolate" || choice == "vanilla" || choice == "twist" )
			{
				flavor = choice;
			}
		}

	}

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

  else
  {
	  cout << "You ordered " << flavor << " ice cream with " << topping << " sauce without sprinkles." << endl;
  }

}

The way the code is structured is somewhat strange, in that you do not allow user input after each question (which is why you get all 3 questions output at once). A more intuitive approach would be to get user input where you are asking the question, for example;

if( flavor == "")
{
//	do-while loops always go through the code once
do{
   cout << "Do you want chocolate, vanilla or twist?" << endl;
   //   actually don't really need the 'choice' variable, can use the 'flavor' string directly
   getline(cin, choice);
   }	
//   no valid response, iterate through again
while (choice != "chocolate" && choice != "vanilla" && choice != "twist");
flavor = choice;
}

and do this for each question.

Thanks...
Sean

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.