1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2012
    Rep Power

    100 animals for 100 dollar


    I have to write a program about the 100 animals for 100 dollar. The program is working fine, but now I can't fix it to get it working if one kind of animal is for free. So if one of the inputs is 0. This is the part that worked, for prices not 0. Tried it with a if/else structur and do-while, but it unfortunaly didn't work.
    PHP Code:
    #include <stdio.h>

    #include <stdlib.h>

    int main(int argcchar *argv[]) {


    int cowchickenmice;
    int acaham;
    int total=10000;
    /* prices in cents*/
    int h=100;
    /* 100 animals total*/

    printf("The animal problem\n");                         
    printf("price cow: ");
    scanf("%d", &cow);
    printf("price chicken : ");
    scanf("%d", &chicken);

    printf("price mice :");
    scanf("%d", &m);
    ac=0ac<=totaal/cowac++) {            
    ah=0ah<=(totaal-ac*cow)/chickenah++) {                          

    ac*chicken+ah*chicken+am*mice==total && ac+ah+am==h){



  2. #2
  3. Contributing User
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Aug 2011
    Rep Power
    Are you quite sure your program is correct? After I change totaal to total, and scanf("%d", &m); to scanf("%d", &mice); the program gives outputs of
    0 20 80
    1 19 80
    2 18 80
    3 17 80
    4 16 80
    for the prices 1000, 300, and 50.

    The animals add to 100 but when I take the matrix product of these with the prices (in dollars) I get
    100 107 114 121 128

    Well, I see the problem in your code. You've lost track of your ac's and ah's.

    Originally Posted by http://www.braingle.com/brainteasers/20263/farm-animals.html
    Your objective is to buy exactly 100 farm animals with exactly 100 dollars. You must buy at least 1 of each animal. You may need some paper!

    The Costs:
    Cows: $10 each
    Pigs: $ 3 each
    Chickens: $0.50 each
    1 pig and 4 chickens would cost 5 bucks, and would be 5 animals. Whoot.
    [code]Code tags[/code] are essential for python code and Makefiles!
  4. #3
  5. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Woodland Hills, Los Angeles County, California, USA
    Rep Power
    What is the world coming to? It is possible to solve this problem without a computer at all, just pencil and paper and a little common sense.
    Up the Irons
    What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
    "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
    Down with Sharon Osbourne

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo

IMN logo majestic logo threadwatch logo seochat tools logo