| | |
another program
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Oct 2008
Posts: 47
Reputation:
Solved Threads: 0
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?
C++ Syntax (Toggle Plain Text)
#include <iostream> #include <string> using namespace std; int main() { string softserve = "", topping = "", sprinkles = ""; string order; do { if (softserve == "") cout << "Do you want chocolate, vanilla or twist?" << endl; if (topping == "") cout << "Hot fudge, chocolate or strawberry sauce?" << endl; if (sprinkles == "") cout << "Do you want sprinkles (yes/no)?" << endl; getline(cin, order); if ((order == "chocolate") || (order == "vanilla") || (order == "twist")) softserve = order; if ((order == "hot fudge") || (order == "chocolate") || (order == "strawberry")) topping = order; if ((order == "yes") || (order == "no")) sprinkles = order; } while ((softserve == "") || (topping == "") || (sprinkles == "")); if (sprinkles == "yes") cout << "You ordered " << softserve << " ice cream with " << topping << " sauce and sprinkles." << endl; else if (sprinkles == "no") cout << "You ordered " << softserve << " ice cream with " << topping << " sauce without sprinkles." << endl; }
Its not necessary to initialize std::strings with blanks because that is the default. Just declare them like this:
I think your program needs more cin statements for data entry.
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.
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:
C++ Syntax (Toggle Plain Text)
#include <iostream> #include <string> using namespace std; int main() { string softserve, topping, sprinkles; string order; do { if (softserve == "") cout << "Do you want chocolate, vanilla or twist?\n"; // endl not needed here if (topping == "") <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.
•
•
Join Date: Oct 2008
Posts: 47
Reputation:
Solved Threads: 0
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.
•
•
Join Date: Oct 2008
Posts: 47
Reputation:
Solved Threads: 0
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.
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.
![]() |
Similar Threads
- Playing .Wav/MIDI files in a Visual Basic Program (Visual Basic 4 / 5 / 6)
- What's the HARDEST program you've written? (Computer Science)
- Cool little Program to disable startup programs (Windows NT / 2000 / XP)
- Program is shutting down right after program is executed (C++)
- 3d Program (Game Development)
Other Threads in the C++ Forum
- Previous Thread: Inter-class instance pointer problems
- Next Thread: Copying Vectors
| Thread Tools | Search this Thread |
api array based beginner binary bitmap c++ c/c++ calculator char char* class classes coding compile compiler console conversion count data database delete desktop developer directshow dll dynamic dynamiccharacterarray email encryption error file forms fstream function functions game getline google graph homeworkhelper iamthwee ifstream input int integer lib linkedlist linker linux list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return rpg sorting string strings struct template templates test text tree unix url vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






