Small tricky Point For New Learner, NEED HELP!

Home Forums Programming Small tricky Point For New Learner, NEED HELP!

Viewing 1 post (of 1 total)
  • Author
    Posts
  • #1450
    submeyar
    Member

    INTRODUCTION OF CODE:
    This is a small game, named Subtracting Game. here User and Computer Subtract the Specific Number that they decided to be subtracted from the Total and make it Zero. BTW nice game for Newbies.

    Well short Intro.Please compile the CODE to understand what the Program do.

    NEED LITTLE HELP:
    Here is a Small Problem i dont Understand the only one Point of this CODE. and that is “remainder = total % (delta + 1);”, OK i know About Modulus and knows what it does. The only thing that i dont know is That why the Programmer has added “1” to delta, actually what is his intention.

    As a programmer do you think that this is a bit tricky point of this program ? “remainder = total % (delta + 1);”.

    CODE :

    #include

    using namespace std;

    int main() {
    int total, n;
    int delta = 0; // Max. number to subtract by each turn.
    int remainder = 0;

    cout cin >> total;
    while (total cout cout cin >> total;
    }
    cout cin >> delta;
    while (delta = total) {
    cout cout cout cin >> delta;
    }
    while (true) {

    // Pick best response and print results.
    // Divide total by delta and use remainder
    // as the number to subtract by.

    remainder = total % (delta + 1);

    if (remainder > 0) {
    total = total – remainder;
    cout } else {
    total–;
    cout }
    cout if (total == 0) {
    cout break;
    }

    // Get user’s response; must be in range 1 to delta.

    cout cout cin >> n;
    while (n delta) {
    cout cout cin >> n;
    }
    total = total – n;
    cout if (total == 0) {
    cout break;
    }
    }
    system(“PAUSE”);
    return 0;
    }

Viewing 1 post (of 1 total)
  • You must be logged in to reply to this topic.