• Post Reply Bookmark Topic Watch Topic
  • New Topic

Modulus problems?  RSS feed

Doe Smith
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey there! This is part of an assignment I have to do, and I've been tearing my hair out trying to solve it.

This is a test case for my assignment:

Enter the number of friends; 10
Enter the number of rounds of removal; 2
Enter the position of removal for round 1; 2
Enter the position of removal for round 2; 3

Output; 1 3 7 9

So initially, our list of friends is: 1, 2, 3 ... 8, 9, 10 and there will be two rounds of removal. For the first round, we remove every even number (or second number). The next iteration of our list then becomes 1, 3, 5, 7, 9. For the second round, we remove every third number. With this, the final iteration of the list becomes 1, 3, 7 & 9.

We've been given a set of restrictions to make the solving of this problem all the more harder.
  • We are only allowed to use one array in the main method.
  • There must be four methods; two for input, one for removal and one for output.
  • The main method must consist of nothing but variable declarations and method calls.

  • I have every method complete except for the removal method, which is obviously the most complicated part of the program.

    I figure that the index of friends % position is enough to determine if that 'friend' is invited or not; if it returns 0, that friend is not 'invited' and vice versa, but (like usual) it's not that easy.

    Here's the code in question. (Bit too long for a [code] tag, I assume) I'm not looking for straight up answers - instead, I'm looking for a nod in the correct direction. Any and all help is appreciated, thank you! I'll try to answer whatever questions you may have.
    Campbell Ritchie
    Posts: 56546
    • Likes 1
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Welcome to the Ranch

    Please post all your code in the code tags; people often post much more than you have on pastebin. Many people are reluctant to follow external links like that.
    Now ignore the code. Your instructions sound difficult, so you should regard them as impossible to code. You need to go through them with pencil and paper until you can reliably delete however many. When you have done that you will have some chance of getting it into code. What does remove every other number mean? Does it mean removing numbers dividing by 2? That is not the same. Least of all when you get on to your second array 1 3 5 7 9.

    You realise you cannot alter the size of an array, nor remove elements? You can only replace elements with others. You can however decide which elements to keep and copy them into a second array.
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!