Quantcast

Got Homework?

Connect with other students for help. It's a free community.

  • across
    MIT Grad Student
    Online now
  • laura*
    Helped 1,000 students
    Online now
  • Hero
    College Math Guru
    Online now

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

jesssica Group Title

WHO LIKES CHICKEN NUGGETS? help with writing a c++ program that outputs diff combinations of chicken nugget packs...

  • 2 years ago
  • 2 years ago

  • This Question is Closed
  1. jesssica Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    the problem is the nuggets come in packs of 6 9 and 20 and i have to make a program that outputs the different pack combinations that the user can buy for an order. for example,

    • 2 years ago
  2. jaskaran Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    have you written any code for it?

    • 2 years ago
  3. jesssica Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    if the user wanted 54 nuggets, they could have nine packs of six or five packs of nine.

    • 2 years ago
  4. jesssica Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    *six packs of nine.

    • 2 years ago
  5. bahrom7893 Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    Ohhh i see

    • 2 years ago
  6. jesssica Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    and yeah i didnt write code yet. i am still stuck on making a plan...

    • 2 years ago
  7. bahrom7893 Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    this is like finding the factors...

    • 2 years ago
  8. bahrom7893 Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    pulling up old codes for ideas...

    • 2 years ago
  9. jaskaran Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    this is pset2 from 6.00 and i have done it.

    • 2 years ago
  10. jesssica Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    do i have to do something with the %.

    • 2 years ago
  11. jaskaran Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    no, first try to write a simple code or read the problem again

    • 2 years ago
  12. jesssica Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    ummm. i am so stuck. do i just write out all the combinations myself ?

    • 2 years ago
  13. jesssica Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    oh and there is a cap of 100.

    • 2 years ago
  14. jaskaran Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    i am not able to tell you clearly about it since you have not written any code.

    • 2 years ago
  15. bahrom7893 Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    ok let's start with basics: #include <iostream> using namespace std; int main() { int amt; cout << "How many nuggets would you like to purchase?" << endl; cin >> amt; ...... hmm now

    • 2 years ago
  16. bahrom7893 Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    oh btw the user has to buy something that's a multiple of these. I mean what if he buys less than 6, or what if he buys 7, or 8, etc.

    • 2 years ago
  17. jaskaran Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    then it cannot be bought

    • 2 years ago
  18. bahrom7893 Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    So i guess we could add the following: do { cout << "Please choose a different number: " cin >> ant; } while (a%6!=0 || a%9!=0 || a%20!=0 );

    • 2 years ago
  19. jesssica Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    #include <iostream> #include <iomanip> using namespace std; void main() { int p6, p9, p20, order; cout<<"How many nuggets would you like to order?"; cin>>order; p20=order/20; cout<<p20<<" 20 piece package."<<endl; } kay there. so that works for if i input 20. lol.

    • 2 years ago
  20. bahrom7893 Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    lol that's like... *facepalm*

    • 2 years ago
  21. jaskaran Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    you guys are using c++, but i wrote it in python

    • 2 years ago
  22. jesssica Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    this is why i need help.

    • 2 years ago
  23. bahrom7893 Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    jask, give me the algorithm, i'll try to translate it.

    • 2 years ago
  24. jaskaran Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    ok i'll give you the most basic version of this program

    • 2 years ago
  25. jaskaran Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    here """To find the sizes of McNuggets packages""" from math import * number = input("Enter the number of McNuggets you want to buy :") a=b=c=1 available = True while available == True: a1=number/a + 1 b1=number/b + 1 c1=number/c + 1 for a in range(0,a1): for b in range(0,b1): for c in range(0,c1): if number == 6*a + 9*b + 20*c : print "you need",a,"number of",6,"packs" print "you need",b,"number of",9,"packs" print "you need",c,"number of",20,"packs" print "of McNuggets" print "---------------------------" available=False print "Thank you for Buying and Have a nice day!!!" break

    • 2 years ago
  26. jaskaran Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    this for the first time i wrote it, a long time ago

    • 2 years ago
  27. jaskaran Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    it may not be that much elegant but it works, not for every input

    • 2 years ago
  28. jesssica Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    okay so why are we dividing by the variable plus 1?

    • 2 years ago
  29. bahrom7893 Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    oh boy, i hoped it would work for all inputs, i mean come on, i can write out like 50 if else statements too for all possible inputs..

    • 2 years ago
  30. jesssica Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    that ^^

    • 2 years ago
  31. bahrom7893 Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    there's no way in heck im doin that lol.. let me think

    • 2 years ago
  32. bahrom7893 Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    okay i see...

    • 2 years ago
  33. jesssica Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    at least 6 9 and 20 multiples can be done with, for example, an if (order%6==0) p6=order/6; cout<<p6 "6-piece packages."<<endl; etc

    • 2 years ago
  34. bahrom7893 Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    writing the code in a compiler.. not sure if the right idea.. just yet

    • 2 years ago
  35. jaskaran Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    okay @bahrom7893 this solution is only for this specific problem, i also have a more general solution

    • 2 years ago
  36. arcticf0x Group Title
    Best Response
    You've already chosen the best response.
    Medals 2

    I wish i could've helped you with the code, but still i found this http://en.wikipedia.org/wiki/Coin_problem#McNugget_numbers hope that helps!

    • 2 years ago
  37. bahrom7893 Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    is that federer?

    • 2 years ago
  38. jesssica Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    aw thankss.

    • 2 years ago
  39. bahrom7893 Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    mehh my method didnt work

    • 2 years ago
  40. jaskaran Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    in fact this program can be generalized too, just take input three packet sizes from user and replace them with 6, 9, 20 and there you have it.

    • 2 years ago
  41. jesssica Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    so ask the user to guess first?

    • 2 years ago
  42. jaskaran Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    the packet sizes as well as the number of mcnuggets they want.

    • 2 years ago
  43. arcticf0x Group Title
    Best Response
    You've already chosen the best response.
    Medals 2

    @bahrom7893 Yep, Roger Federer :D

    • 2 years ago
  44. thinkpad20 Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    This problem (albeit in python) is on one of the problem sets for course 6.00, problem set 2 to be precise. So you might want to ask there. I've done it, and could give you my code, but it's really basically the same as jaskaran's.

    • 2 years ago
  45. thinkpad20 Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    the reason you divide by the variable is because, for example, if you have a box of nuggets with 20 pieces, you know that the maximum number of boxes you could have (and thus the maximum you need to test) is your target/20. As for the +1, it's because the python range function gives you numbers until one behind the number you input, e.g.: range (0,5) 0, 1, 2, 3, 4 C++ may or may not be similar.

    • 2 years ago
  46. jesssica Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    does python solve for a b and c in that equation num==2*a + 9*b + 20*c ? cause i dont think c++ does .

    • 2 years ago
  47. jesssica Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    okay i am trying to understand jaskarans program...if the input was 6, then how would it print b and c as 0 if they were initialized as 1 ?

    • 2 years ago
  48. thinkpad20 Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    I think the reason he put in the line a=b=c=1 is just to initialize them as numbers. But actually I don't think it really matters, since either way you're simply looking at a, b and c values iterated between 0 and number/(size of nugget box). I'll paste my code for it, as upon second look mine is a little different (I don't use a while loop for example) and a bit simpler, and also mine has annotations that might make it more easy to understand. Anyway, here's mine: http://pastebin.com/dpJuFujR Actually I disagree with jaskarans' use of the while loop because, upon a cursory glance, it seems to be irrelevant: the value starts as true, the for statements run, and then the value is false. The program would run just as well without any while statement. As for what you asked, no, python doesn't actually solve (algebraically) the equation as you said. I'm sure you can write a program that solves algebraic equations, but the much more simple answer when dealing with a program language is to use what a computer is good at: trying out a bunch of stuff at blazing speed and testing if it's the right answer.

    • 2 years ago
  49. thinkpad20 Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    As a matter of fact, looking back at my program now, the S=0 M=0 L=0 statements I made at the beginning are also irrelevant. S, M, and L values are chosen by the for function, so even if I had not mentioned them at all in the beginning it still wouldn't matter.

    • 2 years ago
  50. jesssica Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    i guess python and c++ work differently because i tried translating yours and it is giving me a neverending loop. i am not sure c++ is capable of checking the range by itself.. idk. thanks though !

    • 2 years ago
  51. pre-algebra Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

    This is naturally a recursive problem, and since it's a Sunday evening and I'm bored, I wrote this little hack that solves your problem: http://ideone.com/2iYBp

    • 2 years ago
  52. arcticf0x Group Title
    Best Response
    You've already chosen the best response.
    Medals 2

    @pre-algebra It works! But not for all inputs. Also please could you explain this part http://ideone.com/01WcK Thanks!

    • 2 years ago
  53. thinkpad20 Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    jesssica - there shouldn't be any possibility of an infinite loop occurring with only for statements; they have a strict beginning and end. Or at least, Python is that way and I would assume C++ is as well. Are you sure you're not using a while statement or other loop-generating code?

    • 2 years ago
  54. jesssica Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    thanks everyone, i ended up using mod and an else of subtracting from the initial and remainders.

    • 2 years ago
    • Attachments:

See more questions >>>

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...

23

  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.