Thread: another do while question

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Feb 2009
    Posts
    30

    another do while question

    i am working on this program for my class, and i almost have this figured out. the problem is that since chocolate can be referred to as 2 different answers, that is where my program is going wacky. once i type in chocolate the first time, the first question is supposed to go away and ask me the second one. once i answer that, the second question is supposed to go away and ask me the final question. the program is working for every thing else (strawberry, hot fudge) except chocolate. i can type in chocolate the first time, the 1st question goes away, but once i type it in again, the second and third question are asked again and again and again (until the counter reaches 100).
    if you need me to explain this better let me know.
    here is the assignment description:
    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. Use the screen shots
    below as a guide. 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.

    Code:
    #include <iostream>
    #include <string>
    using namespace std;
    
    int main()
    {
    	string icecream = "", answer, sauce = "", sprinkles = "";
    
    	int kwb = 0;
    	do
    	{
    		if (kwb++ > 100)
    			break;
    		if (icecream == "")
    			cout << "Do you want chocolate, vanilla or twist? " << endl;
    		if (sauce == "")
    			cout << "Hot fudge, chocolate or strawberry sauce? " << endl;
    		if (sprinkles == "")
    			cout << "Do you want sprinkles (yes/no)? " << endl;
    		getline (cin, answer);
    		if ((answer == "chocolate")&&(sauce == ""))
    		{
    			icecream = "chocolate";
    			
    				
    		}
    
    		else
    		{
    			if ((answer == "vanilla")||(answer == "twist"))
    				icecream = answer;
    			if ((answer == "hot fudge")||(answer == "strawberry"))
    				sauce = answer;
    			if ((answer == "yes")||(answer == "no"))
    				sprinkles = answer;
    		}
    		
    		
    
    
    	} while ((icecream == "")||(sauce == "")||(sprinkles == ""));
    
    	if (sprinkles == "yes")
    		cout << "You ordered " << icecream << " ice cream with " << sauce << " sauce and sprinkles." << endl;
    	if (sprinkles == "no")
    		cout << "You ordered " << icecream << " ice cream with " << sauce << " sauce without sprinkles." << endl;
    }
    thanks for the help guys.
    Last edited by kbpsu; 03-23-2009 at 11:50 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Alice....
    By Lurker in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 06-20-2005, 02:51 PM
  2. Debugging question
    By o_0 in forum C Programming
    Replies: 9
    Last Post: 10-10-2004, 05:51 PM
  3. Question about pointers #2
    By maxhavoc in forum C++ Programming
    Replies: 28
    Last Post: 06-21-2004, 12:52 PM
  4. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM
  5. Question, question!
    By oskilian in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 12-24-2001, 01:47 AM