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

Re: another program

 
0
  #21
Oct 14th, 2008
ok thanks emotionalone
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 32
Reputation: emotionalone is an unknown quantity at this point 
Solved Threads: 4
emotionalone emotionalone is offline Offline
Light Poster

Re: another program

 
0
  #22
Oct 14th, 2008
Just checking the forums at school before I go home.
Try what I just posted but instead of for() use while() and have int a, b, c; tell the algorithm whether or not the question should keep looping.
  1. while( ... && a )
  2. {
  3. while( ... & b )
  4. {
  5. while( ... & c)
  6. }
  7. }

Somethign like that. That way the values a, b, c (which should be either 0 or different than zero - the convention I guess is to make it 1 for different than zero).
I'll be back later!
Last edited by emotionalone; Oct 14th, 2008 at 10:17 pm.
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
  #23
Oct 14th, 2008
Thanks emotionalone. But, I have to admit, I am confused with the a, b, c.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 32
Reputation: emotionalone is an unknown quantity at this point 
Solved Threads: 4
emotionalone emotionalone is offline Offline
Light Poster

Re: another program

 
0
  #24
Oct 15th, 2008
Last night as I was typing this message my internet got cut off U_U
Here is what I had for you last night but couldn't post it then:

I could finally solve it.
I used the idea you had on the draft you posted on the first page.
You wanna have a while() that only checks whether or not the 3rd answer string is empty or not. Then just do 3 if() each with 3 comparisons, 1 with the softserve, 1 with the topping and 1 with the sprinkles. Be careful with the order of these if() statements because they will all get evaluated each time you run through the loop and if a string changes, it should change where it won't make other if() true.
You will ask for the softserve as long as the softserve stream is empty, you can make sure it stays empty when an invalid input has been made by not copying the string directly to it but using an auxiliary stream, which you will use for all inputs.
I'll give you a lil hint code
  1. while()
  2. {
  3. if();
  4. if();
  5. if();
  6. getline(cin, choice) //choice is the auxiliary string
  7. if();
  8. if();
  9. if();
  10. }
The first set of 3 if()'s will print the question, the second set will decide which choices compare the input to.
I have the finished code but I thought you might like some help instead of the code itself. I can post the code the next time I log in if that's what you need or you can post yours after reading this post

Good luck.
Last edited by emotionalone; Oct 15th, 2008 at 9:12 am.
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
  #25
Oct 15th, 2008
Thanks emotionalone. I appreciate your time and effort. This language is very confusing to me. I felt I was close with the one of the first page. Could you please PM me the code?
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 32
Reputation: emotionalone is an unknown quantity at this point 
Solved Threads: 4
emotionalone emotionalone is offline Offline
Light Poster

Re: another program

 
0
  #26
Oct 15th, 2008
Sorry it took me so long, I had left the code at home and didn't have time to write it again in the middle of the day. Here is the code
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. string softserve, topping, sprinkles;
  8. string choice;
  9.  
  10. while( sprinkles == "")
  11. {
  12. if( softserve == "" )
  13. cout << "Do you want chocolate, vanilla or twist?" << endl;
  14. if( topping == "")
  15. cout << "Hot fudge, chocolate or strawberry sauce?" << endl;
  16. if( sprinkles == "")
  17. cout << "Do you want sprinkles (yes/no)?" << endl;
  18.  
  19. getline(cin, choice);
  20.  
  21. if( sprinkles == "" && topping != "" && softserve !="")
  22. if( choice == "yes" || choice =="no" )
  23. sprinkles = choice;
  24.  
  25. if( sprinkles == "" && topping == "" && softserve !="")
  26. if( choice == "hot fudge" || choice =="chocolate" || choice == "strawberry" )
  27. topping = choice;
  28.  
  29.  
  30. if( sprinkles == "" && topping == "" && softserve =="")
  31. if( choice == "chocolate" || choice =="vanilla" || choice == "twist" )
  32. softserve = choice;
  33.  
  34. }
  35.  
  36. if (sprinkles == "yes")
  37. cout << "You ordered " << softserve << " ice cream with " << topping << " sauce and sprinkles." << endl;
  38. else
  39. cout << "You ordered " << softserve << " ice cream with " << topping << " sauce without sprinkles." << endl;
  40. cout << "Press a key to continue..." << endl;
  41. system("pause>nul");
  42. }
It should work just how you want it to. Any questions or comments don't hesitate.
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
  #27
Oct 16th, 2008
thank you very much. i may have more questions about other programs later.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 32
Reputation: emotionalone is an unknown quantity at this point 
Solved Threads: 4
emotionalone emotionalone is offline Offline
Light Poster

Re: another program

 
0
  #28
Oct 16th, 2008
Just for forum reference(lies XD), you can mark this thread as solved =3
Last edited by emotionalone; Oct 16th, 2008 at 8:44 pm.
Reply With Quote Quick reply to this message  
Join Date: Mar 2009
Posts: 3
Reputation: star4ker is an unknown quantity at this point 
Solved Threads: 0
star4ker star4ker is offline Offline
Newbie Poster

Re: another program

 
0
  #29
Mar 16th, 2009
I was looking at this solution for the problem since I was having the same difficulty with it. I found an issue with the supposed solved code for the problem. If the user enters a yes or a no as their choice for sprinkles, the program still repeats all the questions. The sprinkles answer will only be taken if it is the last questions answered. Here is my final code. Any help?:

  1. int main()
  2. {
  3. string flavor, topping, sprinkles, choice;
  4. int terminate = 0;
  5.  
  6. while( sprinkles == "")
  7. {
  8. if (terminate++ > 30)
  9. {
  10. break;
  11. }
  12.  
  13. if( flavor == "")
  14. {
  15. cout << "Do you want chocolate, vanilla or twist?" << endl;
  16. }
  17.  
  18. if( topping == "")
  19. {
  20. cout << "Hot fudge, chocolate or strawberry sauce?" << endl;
  21. }
  22.  
  23. if( sprinkles == "")
  24. {
  25. cout << "Do you want sprinkles (yes/no)?" << endl;
  26. }
  27.  
  28. getline(cin, choice);
  29.  
  30. if( sprinkles == "" && topping != "" && flavor != "")
  31. {
  32. if( choice == "yes" || choice =="no" )
  33. {
  34. sprinkles = choice;
  35. }
  36. }
  37.  
  38. if( sprinkles == "" && topping == "" && flavor != "")
  39. {
  40. if( choice == "hot fudge" || choice == "chocolate" || choice == "strawberry" )
  41. {
  42. topping = choice;
  43. }
  44. }
  45.  
  46.  
  47. if( sprinkles == "" && topping == "" && flavor == "")
  48. {
  49. if( choice == "chocolate" || choice == "vanilla" || choice == "twist" )
  50. {
  51. flavor = choice;
  52. }
  53. }
  54.  
  55. }
  56.  
  57. if (sprinkles == "yes")
  58. {
  59. cout << "You ordered " << flavor << " ice cream with " << topping << " sauce and sprinkles." << endl;
  60. }
  61.  
  62. else
  63. {
  64. cout << "You ordered " << flavor << " ice cream with " << topping << " sauce without sprinkles." << endl;
  65. }
  66.  
  67. }
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