another program

Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Oct 2008
Posts: 47
Reputation: joed13k1941 is an unknown quantity at this point 
Solved Threads: 0
joed13k1941 joed13k1941 is offline Offline
Light Poster

another program

 
0
  #1
Oct 12th, 2008
Hey. Thanks for all of the help with my other questions. This forum has been very helpful. In this program, there is a 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. So, if I enter chocolate for the first question, it automatically skips the second (which asks for type of sauce) and goes right to the last question. How can I arrange it so that I can get input data to get an output such as: You have selected chocolate ice cream with hot fudge sauce and sprinkles?


  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4. int main()
  5. {
  6. string softserve = "", topping = "", sprinkles = "";
  7. string order;
  8. do
  9. {
  10. if (softserve == "")
  11. cout << "Do you want chocolate, vanilla or twist?" << endl;
  12. if (topping == "")
  13. cout << "Hot fudge, chocolate or strawberry sauce?" << endl;
  14. if (sprinkles == "")
  15. cout << "Do you want sprinkles (yes/no)?" << endl;
  16. getline(cin, order);
  17. if ((order == "chocolate") || (order == "vanilla")
  18. || (order == "twist"))
  19. softserve = order;
  20. if ((order == "hot fudge") || (order == "chocolate")
  21. || (order == "strawberry"))
  22. topping = order;
  23. if ((order == "yes") || (order == "no"))
  24. sprinkles = order;
  25. } while ((softserve == "") || (topping == "") || (sprinkles == ""));
  26.  
  27. if (sprinkles == "yes")
  28. cout << "You ordered " << softserve << " ice cream with " << topping
  29. << " sauce and sprinkles." << endl;
  30.  
  31. else if (sprinkles == "no")
  32.  
  33. cout << "You ordered " << softserve << " ice cream with " << topping
  34. << " sauce without sprinkles." << endl;
  35. }
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,378
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1466
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: another program

 
0
  #2
Oct 12th, 2008
Its not necessary to initialize std::strings with blanks because that is the default. Just declare them like this: std::string softserve, topping, sprinkles;
I think your program needs more cin statements for data entry.
Last edited by Ancient Dragon; Oct 12th, 2008 at 9:11 pm.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 47
Reputation: joed13k1941 is an unknown quantity at this point 
Solved Threads: 0
joed13k1941 joed13k1941 is offline Offline
Light Poster

Re: another program

 
0
  #3
Oct 12th, 2008
Well, I was just wondering why if the user enters chocolate for the first question, why does it input chocolate for the second question automatically.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,378
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1466
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: another program

 
0
  #4
Oct 12th, 2008
If you wrote that then you should know why. You should also reformat the code to make it easier to read and understand. Example below:
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4. int main()
  5. {
  6. string softserve, topping, sprinkles;
  7. string order;
  8. do
  9. {
  10. if (softserve == "")
  11. cout << "Do you want chocolate, vanilla or twist?\n"; // endl not needed here
  12. if (topping == "")
  13. <snip>
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 47
Reputation: joed13k1941 is an unknown quantity at this point 
Solved Threads: 0
joed13k1941 joed13k1941 is offline Offline
Light Poster

Re: another program

 
0
  #5
Oct 12th, 2008
Ok. I did write the program. I wrote it using all of the variables I was supposed to use based on the assignment. After running it, I noticed this chocolate problem and was just looking for help.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 47
Reputation: joed13k1941 is an unknown quantity at this point 
Solved Threads: 0
joed13k1941 joed13k1941 is offline Offline
Light Poster

Re: another program

 
0
  #6
Oct 12th, 2008
The output should look like this:
Attached Thumbnails
screen shot.jpg  
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,378
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1466
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: another program

 
0
  #7
Oct 12th, 2008
I got that same output with the code you posted.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 47
Reputation: joed13k1941 is an unknown quantity at this point 
Solved Threads: 0
joed13k1941 joed13k1941 is offline Offline
Light Poster

Re: another program

 
0
  #8
Oct 12th, 2008
It's not the same. With my program, if you enter chocolate first, it skips right to the sprinkles question. It automatically enters chocolate for question 2. Another example (if you want to run it), is that if I enter twist first, and then chocolate for the sauce, and then yes or no for sprinkles (does not matter), it overrides the twist and says I ordered chocolate ice cream with chocolate sauce, when I really input twist ice cream with chocolate sauce.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,378
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1466
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: another program

 
0
  #9
Oct 13th, 2008
The instructions you originally posted are very confusing. Is that the exact wording of the assignment, or just how you interpreted it. Please post exact assignment.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 47
Reputation: joed13k1941 is an unknown quantity at this point 
Solved Threads: 0
joed13k1941 joed13k1941 is offline Offline
Light Poster

Re: another program

 
0
  #10
Oct 13th, 2008
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.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC