943,895 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Marked Solved
  • Views: 3284
  • C++ RSS
You are currently viewing page 3 of this multi-page discussion thread; Jump to the first page
Oct 14th, 2008
0

Re: another program

ok thanks emotionalone
Reputation Points: 10
Solved Threads: 0
Light Poster
joed13k1941 is offline Offline
47 posts
since Oct 2008
Oct 14th, 2008
0

Re: another program

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.
C++ Syntax (Toggle Plain Text)
  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.
Reputation Points: 10
Solved Threads: 4
Light Poster
emotionalone is offline Offline
33 posts
since Oct 2008
Oct 14th, 2008
0

Re: another program

Thanks emotionalone. But, I have to admit, I am confused with the a, b, c.
Reputation Points: 10
Solved Threads: 0
Light Poster
joed13k1941 is offline Offline
47 posts
since Oct 2008
Oct 15th, 2008
0

Re: another program

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
C++ Syntax (Toggle Plain Text)
  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.
Reputation Points: 10
Solved Threads: 4
Light Poster
emotionalone is offline Offline
33 posts
since Oct 2008
Oct 15th, 2008
0

Re: another program

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?
Reputation Points: 10
Solved Threads: 0
Light Poster
joed13k1941 is offline Offline
47 posts
since Oct 2008
Oct 15th, 2008
0

Re: another program

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
C++ Syntax (Toggle Plain Text)
  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.
Reputation Points: 10
Solved Threads: 4
Light Poster
emotionalone is offline Offline
33 posts
since Oct 2008
Oct 16th, 2008
0

Re: another program

thank you very much. i may have more questions about other programs later.
Reputation Points: 10
Solved Threads: 0
Light Poster
joed13k1941 is offline Offline
47 posts
since Oct 2008
Oct 16th, 2008
0

Re: another program

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.
Reputation Points: 10
Solved Threads: 4
Light Poster
emotionalone is offline Offline
33 posts
since Oct 2008
Mar 16th, 2009
0

Re: another program

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?:

C++ Syntax (Toggle Plain Text)
  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. }
Reputation Points: 10
Solved Threads: 0
Newbie Poster
star4ker is offline Offline
3 posts
since Mar 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Inter-class instance pointer problems
Next Thread in C++ Forum Timeline: Copying Vectors





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC