2 C++ and 1 PB Questions

macavenger

Registered
Ok, I have three questions here. Hopefully someone will be able to answer at least one of them ;)

1)How can I get a program (in C++) to accept input from the keyboard without having to press enter? I would like to make a menu where the user can just type their selection number to choose from the menu, without having to press return or enter afterwards.

2)The random number generator on my computer is being weird. I have written a program for my CS201 class that rolls two dice 36000 times each, and at each roll calculates the sum of the two dice. after it is done, it displays how many times each possible sum was rolled. However, for some reason, the number rolled on the first die is always odd, and the number rolled on the second die is always even, or vice versa. This of course totally messes up the output, as the sum is always odd. When I run the program on another computer, it works fine. Anyone know what I can do about this?

My code (I do of course have the necesarry #include statements, hopefully the code won't be too mangled):

Code:
int main () {
    srand(time(0));
    int sum[13]={0}, die_1=0, die_2=0;
    for(int roll=1; roll<=36000;roll++)
    {
        die_1=1+rand()%6;
        die_2=1+rand()%6;
        sum[die_1+die_2]++;
    }
    cout<< setw(5)<<"Sum"<< setw(10)<<"Rolls"<< endl;
    for(int i=2; i<=12; i++)
    {
        cout<< setw(5)<< i;
        cout<< setw(10)<< sum[i]<< endl;
    }
    return 0;
}

3)For some reason, the Project Builder debugger has started ignoring breakpoints. It worked fine the first few times I used it, but lately I can put in a breakpoint on every line, and it will just blithely run through the program, never stopping once. I have no clue what I did to cause this. Anyone know how to fix it?

Any help that you can provide would be greatly appreciated. Thanks!
 
What, are my questions really that hard? Or it it just that no one wants to answer me? I am beginning to feel unloved here :(;) Ok, here is a simpler question. Anyone know where I can go to find answers to my previous questions?
 
You might want to give it more than one day, I'd bet not every person checks the board with extreme regularity...

As far as your oddity with rand(), it's actually quite simple, in that, rand() isn't that good. Try switching your srand() to srandom() and rand() to random() and see if things look a whole lot better (the random manpage has a quick blurb on what is wrong with rand()).
 
Can anybody answer my other two questions, or tell me where I can go to find the answers? Please? I am most interested in the debugger problem, as debugging my applications in the command line can be rather annoying. Is there some other debugger available that I can use instead of project builder if no one knows how i can fix PB? HELP!!!!
 
Back
Top