943,666 Members | Top Members by Rank

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

Re: another program

these are the two screen shots he gave me as well
Attached Thumbnails
Click image for larger version

Name:	screen shot.jpg
Views:	9
Size:	37.6 KB
ID:	7705   Click image for larger version

Name:	screen shot 2.jpg
Views:	9
Size:	31.4 KB
ID:	7706  
Reputation Points: 10
Solved Threads: 0
Light Poster
joed13k1941 is offline Offline
47 posts
since Oct 2008
Oct 13th, 2008
0

Re: another program

Sorry, I'll have to get to this tomorrow evening if someone else has not answered your questions by then.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,949 posts
since Aug 2005
Oct 13th, 2008
0

Re: another program

Thanks Ancient Dragon. I really appreciate the help. Hopefully I have it by then.
Reputation Points: 10
Solved Threads: 0
Light Poster
joed13k1941 is offline Offline
47 posts
since Oct 2008
Oct 13th, 2008
0

Re: another program

My first unit using iostream XD
C++ Syntax (Toggle Plain Text)
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8. string softserve, topping, sprinkles;
  9. string order;
  10. do
  11. {
  12. cout << "Do you want chocolate, vanilla or twist?" << endl;
  13. getline(cin, softserve);
  14. }
  15. while( (softserve!="chocolate") && (softserve!="vanilla") && (softserve!="twist") );
  16. do
  17. {
  18. cout << "Hot fudge, chocolate or strawberry sauce?" << endl;
  19. getline(cin, topping);
  20. }
  21. while( (topping!="hot fudge") && (topping!="chocolate") && (topping!="strawberry") );
  22. do
  23. {
  24. cout << "Do you want sprinkles (yes/no)?" << endl;
  25. getline(cin, sprinkles);
  26. }
  27. while( (sprinkles!="yes") && (sprinkles!="no") );
  28. if (sprinkles == "yes")
  29. cout << "You ordered " << softserve << " ice cream with " << topping << " sauce and sprinkles." << endl;
  30. else
  31. cout << "You ordered " << softserve << " ice cream with " << topping << " sauce without sprinkles." << endl;
  32. cout << "Press a key to continue..." << endl;
  33. system("pause>nul");
  34. }
That should work fine.
Here you only accept answers in lowercase. and you do a do{}while(); for each input because you wanna reject each wrong answer for each input, not after all 3 inputs have been made, that would take more lines and achieve the same.
I just copied some of your codes and copy and pasted as I saw fit. My only real contribution, code wise, is the pause at the end, which I searched in cplusplus.com for
Reputation Points: 10
Solved Threads: 4
Light Poster
emotionalone is offline Offline
33 posts
since Oct 2008
Oct 13th, 2008
0

Re: another program

instead of system(pause>nul) why didn't you just simply use cin.get() ? you wouldn't have to have done all that net searching
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,949 posts
since Aug 2005
Oct 13th, 2008
0

Re: another program

My first unit using iostream XD
C++ Syntax (Toggle Plain Text)
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8. string softserve, topping, sprinkles;
  9. string order;
  10. do
  11. {
  12. cout << "Do you want chocolate, vanilla or twist?" << endl;
  13. getline(cin, softserve);
  14. }
  15. while( (softserve!="chocolate") && (softserve!="vanilla") && (softserve!="twist") );
  16. do
  17. {
  18. cout << "Hot fudge, chocolate or strawberry sauce?" << endl;
  19. getline(cin, topping);
  20. }
  21. while( (topping!="hot fudge") && (topping!="chocolate") && (topping!="strawberry") );
  22. do
  23. {
  24. cout << "Do you want sprinkles (yes/no)?" << endl;
  25. getline(cin, sprinkles);
  26. }
  27. while( (sprinkles!="yes") && (sprinkles!="no") );
  28. if (sprinkles == "yes")
  29. cout << "You ordered " << softserve << " ice cream with " << topping << " sauce and sprinkles." << endl;
  30. else
  31. cout << "You ordered " << softserve << " ice cream with " << topping << " sauce without sprinkles." << endl;
  32. cout << "Press a key to continue..." << endl;
  33. system("pause>nul");
  34. }
That should work fine.
Here you only accept answers in lowercase. and you do a do{}while(); for each input because you wanna reject each wrong answer for each input, not after all 3 inputs have been made, that would take more lines and achieve the same.
I just copied some of your codes and copy and pasted as I saw fit. My only real contribution, code wise, is the pause at the end, which I searched in cplusplus.com for
yes, this does work. but, it needs to ask all of the unanswered questions every time. so, if the user enters twist ice cream, it should ask for the sauce and sprinkles (not just the sauce). also, when it is started, it only asks for type of ice cream. it should ask all 3 questions to start
Reputation Points: 10
Solved Threads: 0
Light Poster
joed13k1941 is offline Offline
47 posts
since Oct 2008
Oct 13th, 2008
0

Re: another program

All of the questions need to be inside of the loop I guess. That is what is giving me trouble. Any ideas?
Reputation Points: 10
Solved Threads: 0
Light Poster
joed13k1941 is offline Offline
47 posts
since Oct 2008
Oct 13th, 2008
0

Re: another program

I spoke to my teacher and showed him the problem. He said it is a simple fix but of course he wouldn't tell me. I have been trying dozens of things (moving things around), but I cannot get it to work the way I want.
Reputation Points: 10
Solved Threads: 0
Light Poster
joed13k1941 is offline Offline
47 posts
since Oct 2008
Oct 14th, 2008
0

Re: another program

Any ideas?
Reputation Points: 10
Solved Threads: 0
Light Poster
joed13k1941 is offline Offline
47 posts
since Oct 2008
Oct 14th, 2008
0

Re: another program

I'll work on the code once I get home, right now I got a class and I'm already late =s
But here's an idea:

The first question repeats once.
The second question repeats twice.
The third question repeats thrice

C++ Syntax (Toggle Plain Text)
  1. int i, j, k;
  2. for( i=0; i<3 ; i++)
  3. {
  4. for( j=0; j < 2 && b; j++)
  5. {
  6. for( k=0; k <1 && c; k++)
  7. cout << "Do you want chocolate, vanilla or twist?\n";
  8. cout << "Hot fudge, chocolate or strawberry sauce?\n";
  9. }
  10. cout << "Do you want sprinkles (yes/no)?\n";
  11. if ( i == 0)
  12. cin >> softserver;
  13. if ( i == 1)
  14. cin >> topping;
  15. if ( i == 2)
  16. cin >> sprinkles;
  17. }

Well, I don't think that code may be going anywhere now that I've written some of it. But that's what I could come up in 15 minutes.
I'm 37 minutes late for class XD
Will get back with you...
Reputation Points: 10
Solved Threads: 4
Light Poster
emotionalone is offline Offline
33 posts
since Oct 2008

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