C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old September 18th, 2012, 05:54 PM
blabla789 blabla789 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2012
Posts: 1 blabla789 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 35 m 45 sec
Reputation Power: 0
100 animals for 100 dollar

Hello,

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);
 
    
    
printf("\cow\tchickent\tmice\t\n");
 
 
    
    for(
ac=0ac<=totaal/cowac++) {            
        
        for(
ah=0ah<=(totaal-ac*cow)/chickenah++) {                          
     

            for(
am=0;am<=(totaal-(ac*chicken+ac*cow))/miceam++){          
                
                if(
ac*chicken+ah*chicken+am*mice==total && ac+ah+am==h){

                    
printf("%d\t%d\t%d\t\n"acaham);
    
                }
      
            }
    
        }
  
    }
  
 

return 
0;
     


Reply With Quote
  #2  
Old September 18th, 2012, 10:11 PM
b49P23TIvg's Avatar
b49P23TIvg b49P23TIvg is offline
Contributing User
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Aug 2011
Posts: 3,458 b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 4 Days 6 h 26 m 43 sec
Reputation Power: 403
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.

Quote:
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!

Reply With Quote
  #3  
Old September 18th, 2012, 10:20 PM
Scorpions4ever's Avatar
Scorpions4ever Scorpions4ever is offline
Banned ;)
Dev Shed God 9th Plane (9000 - 9499 posts)
 
Join Date: Nov 2001
Location: Woodland Hills, Los Angeles County, California, USA
Posts: 9,406 Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level) 
Time spent in forums: 2 Months 10 h 17 m 19 sec
Reputation Power: 4080
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

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > 100 animals for 100 dollar

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap