| | |
another program
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Oct 2008
Posts: 32
Reputation:
Solved Threads: 4
My first unit using iostream XD
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
C++ Syntax (Toggle Plain Text)
#include <iostream> #include <string> using namespace std; int main() { string softserve, topping, sprinkles; string order; do { cout << "Do you want chocolate, vanilla or twist?" << endl; getline(cin, softserve); } while( (softserve!="chocolate") && (softserve!="vanilla") && (softserve!="twist") ); do { cout << "Hot fudge, chocolate or strawberry sauce?" << endl; getline(cin, topping); } while( (topping!="hot fudge") && (topping!="chocolate") && (topping!="strawberry") ); do { cout << "Do you want sprinkles (yes/no)?" << endl; getline(cin, sprinkles); } while( (sprinkles!="yes") && (sprinkles!="no") ); if (sprinkles == "yes") cout << "You ordered " << softserve << " ice cream with " << topping << " sauce and sprinkles." << endl; else cout << "You ordered " << softserve << " ice cream with " << topping << " sauce without sprinkles." << endl; cout << "Press a key to continue..." << endl; system("pause>nul"); }
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
•
•
Join Date: Oct 2008
Posts: 47
Reputation:
Solved Threads: 0
•
•
•
•
My first unit using iostream XD
That should work fine.C++ Syntax (Toggle Plain Text)
#include <iostream> #include <string> using namespace std; int main() { string softserve, topping, sprinkles; string order; do { cout << "Do you want chocolate, vanilla or twist?" << endl; getline(cin, softserve); } while( (softserve!="chocolate") && (softserve!="vanilla") && (softserve!="twist") ); do { cout << "Hot fudge, chocolate or strawberry sauce?" << endl; getline(cin, topping); } while( (topping!="hot fudge") && (topping!="chocolate") && (topping!="strawberry") ); do { cout << "Do you want sprinkles (yes/no)?" << endl; getline(cin, sprinkles); } while( (sprinkles!="yes") && (sprinkles!="no") ); if (sprinkles == "yes") cout << "You ordered " << softserve << " ice cream with " << topping << " sauce and sprinkles." << endl; else cout << "You ordered " << softserve << " ice cream with " << topping << " sauce without sprinkles." << endl; cout << "Press a key to continue..." << endl; system("pause>nul"); }
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
•
•
Join Date: Oct 2008
Posts: 32
Reputation:
Solved Threads: 4
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
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...
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)
int i, j, k; for( i=0; i<3 ; i++) { for( j=0; j < 2 && b; j++) { for( k=0; k <1 && c; k++) cout << "Do you want chocolate, vanilla or twist?\n"; cout << "Hot fudge, chocolate or strawberry sauce?\n"; } cout << "Do you want sprinkles (yes/no)?\n"; if ( i == 0) cin >> softserver; if ( i == 1) cin >> topping; if ( i == 2) cin >> sprinkles; }
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...
![]() |
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 binary c++ c/c++ calculator char char* class classes code coding compile console conversion count database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory multiple news number numbertoword output parameter pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock wordfrequency wxwidgets






