   dice program help?
  I'm having trouble with my dice program. I want the program to ask the user if they want to continue after the numbers have been displayed and the total has been shown. But I'm not sure how to arrange the statements to achieve that result? Here what I  have so far.#include <iostream>#include <stdlib.h>#include <time.h>#include <math.h>#include <string>using namespace std;int main(){int n;int i;int l;int u;string answer = "";cout << "enter the number of dice to roll" << endl;    cin >> l;cout << "enter the value of the dice" <<endl;cin >> u;while (answer != "n"){for(i =0;i<l;i++){n = rand () % u +1 ;cout << "individual dice results "<< n <<  endl;}cout << "continue? Y for yes N for no "<<endl;getline(cin, answer);}cout << "Total value" <<n+n << endl;return 0;}   
  simplest would probably be. . .main(){bool done = false;do{// blah blah blahif (answer == 'N') // or some other string comparisondone = true;} while (!done);}   ;  I tried your suggestion for the do while loop but it sends me into an infinite loop and i cant figure out why? any suggestions?   ;  #include <iostream>#include <stdlib.h>#include <time.h>#include <math.h>#include <string>using namespace std;int main(){int n;int i;int l;int u;string answer = "";do{cout << "enter the number of dice to roll" << endl;    cin >> l;cout << "enter the value of the dice" <<endl;cin >> u;for(i =0;i<l;i++){ n = rand () % u +1 ;cout << "indivisual dice results"<< n <<  endl; }cout << "contiue? Y for yes N for no "<<endl;getline(cin, answer);}while (answer != "n");cout << "Total value" <<n+n << endl;return 0;};  Added intending, and fixed the infinte loop problem by changing the getLine to cin::operator>> (and adding some other tweaks)#include <iostream>#include <stdlib.h>#include <time.h>#include <math.h>#include <string>using namespace std;int main(){int n;int i;int l;int u;string answer = "";do{cout << "enter the number of dice to roll" << endl;cin >> l;cout << "enter the value of the dice" <<endl;cin >> u;for(i =0;i<l;i++){n = rand () % u +1 ;cout << "indivisual dice results " << n << endl;}cout << "contiue? Y for yes N for no "<<endl;cin >> answer;}while (answer != "n");cout << "Total value " << n+n << endl;system("pause");return 0;}I've said it before, I'll say it again - getLine is the most worthless piece of crap ever because it doesn't do what you'd expect it to do. Ask Fruny or one of those other STL-knowledgable people what its doing to not block for more input, but its something along the lines of raising an error state in the stream (or something like that).But yeah :PEDIT: Oh, and for future reference, you should enclode blocks of code in [source] [/source] tags so it shows up in a nice pretty box like the one above - makes it a lot easier to read ;)EDIT2: And as a last snide remark - its really nice (as an outside reader) to have intuitive variable names, like numDice, diceValue, etc. Just a humble suggestion ;)   ;  that worked! i will take that advice im still new to programing and this was a program that i thought i would try on my own and i got very serious about geting this little program to work well and it works now. but one question? what dose system("pause") mean?   ;  That adds the little "Press any key to continue..." message at the end, at least on Win32.system is a function to call kernel stuff, its not really used for much until you mess around with files/folders that kind of weird management stuff. (I'm not too sure, I've never used any commands besides "pause" and "cls" - clearscreen). For a full list of commands, type "help" in the command prompt. Or, lol, system("help") might do it too)I'm off to try system("help") now :D :DEDIT: haha, it works ^_^   ;Quote:Original post by MushuI've said it before, I'll say it again - getLine is the most worthless piece of crap ever because it doesn't do what you'd expect it to do. Ask Fruny or one of those other STL-knowledgable people what its doing to not block for more input, but its something along the lines of raising an error state in the stream (or something like that).No, in this case it's very simple. getline() reads up until the next delimiter character (return, by default). In order for the previous read to work, the user hits return (because the console is line buffered). The input is thus some number followed by a newline, and the previous read does not consume the newline. So it is there right away for the getline() call.getline() does exactly what it could be expected to (except for the part where you need to use the free-function version to read a std::string). It's just that line-oriented and non-line-oriented input don't mix very well.Anyway, time to fix more stuff. Still not guaranteed, you see. For one thing, I didn't fix your summation logic ("n+n" is just two times the last rolled value).#include <iostream>#include <cstdlib>#include <ctime>#include <cmath>// note proper C++ spellings for the C standard libraries.#include <string>#include <limits>// I added this one... keep readingusing namespace std;// First, a function to ask for and return an integer value. This will// let us make sure an actual number was entered, and keep asking the user// until we get something.int prompt(const string& initial, const string& error) {  int result;  char garbage;  cout << initial << endl;  while (!(cin >> result && !cin >> garbage)) {    // That reads "until we can read in a number without reading garbage after it,"    // (see here: http://www.parashift.com/c++-faq-lite/input-output.html#faq-15.4)    cin.clear(); // see here: http://www.augustcouncil.com/~tgibson/tutorial/iotips.html    cin.ignore(numeric_limits<streamsize>::max(), '\n');    // Now that we have "fixed" cin, we can prompt again    cout << error << initial << endl;  }  // When we get here, it's because we read something that was valid.  return result;}int main(){  string answer = "";  int n;  // Seed the RNG - just once  srand(time(0));  do {    // Scope your variables as tightly as you can.    // Also note that you don't have to declare them at the beginning of the    // scope. Also notice how we make use of initializers:    int dieCount = prompt("enter the number of dice to roll", "please enter a number.\n");   int dieFaces = prompt("enter the value of the dice", "please enter a number.\n");    for(int i = 0; i < dieCount; i++) { n = rand() % u +1 ; cout << "indivisual dice results " << n << endl;    }   cout << "contiue? Y for yes N for no "<<endl;    getline(cin, answer);  } while (answer != "n");  cout << "Total value " << n+n << endl;  system("pause");};Quote:Original post by Mushu...#include <iostream>#include <cstdlib>#include <ctime>#include <cmath>// note proper C++ spellings for the C standard libraries.#include <string>#include <limits>// I added this one... keep readingusing namespace std;// First, a function to ask for and return an integer value. This will// let us make sure an actual number was entered, and keep asking the user// until we get something.int prompt(const string& initial, const string& error) {  int result;  char garbage;  cout << initial << endl;  while (!(cin >> result && !cin >> garbage)) {    // That reads "until we can read in a number without reading garbage after it,"    // (see here: http://www.parashift.com/c++-faq-lite/input-output.html#faq-15.4)    cin.clear(); // see here: http://www.augustcouncil.com/~tgibson/tutorial/iotips.html    cin.ignore(numeric_limits<streamsize>::max(), '\n');    // Now that we have "fixed" cin, we can prompt again    cout << error << initial << endl;  }  // When we get here, it's because we read something that was valid.  return result;}int main(){  string answer = "";  int n;  // Seed the RNG - just once  srand(time(0));  do {    // Scope your variables as tightly as you can.    // Also note that you don't have to declare them at the beginning of the    // scope. Also notice how we make use of initializers:    int dieCount = prompt("enter the number of dice to roll", "please enter a number.\n");   int dieFaces = prompt("enter the value of the dice", "please enter a number.\n");    for(int i = 0; i < dieCount; i++) { n = rand() % u +1 ; cout << "indivisual dice results " << n << endl;    }Call me crazy, but after that tirade, did you just forget to initialize or even declare what exactly the u that you just modulus'd your rand statement with?  I'm sure it was just an overlooked detail, but perhaps it would be best to look for these before you make such a patronizing post?My two cents, something to chew on,Vopisk   ;  What are you trying to do in this line?cout <   