473,395 Members | 1,885 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Animals last time

Ok i understand your frustration - but I too am quite frustrated. This
assignment was due yesterday, and i am still not getting the right
calculations. I said "pigs and chickens" because they are barn
animals, and that is really all the program requires. An animal with 2
legs and one with four. I changed it to cowboys and horses because it
seemed more...i dunno...realistic??

Anyways, short of the right numbers printing out, I got the program
working flawlessly. The calculation section looks like:

void Print_Possibilities(int min, int max)
{
int index; // The index number to track combinations
int legs; // The minimum number of legs
int horses; // Number of horses
int cowboys; // Number of cowboys

for (legs = min; legs < max; legs++)
{
for (index = min_cowboys; index < legs; index ++)
{
if ((index * legs_cowboys * min_cowboys) < legs)
{
if ((legs - index * legs_cowboys * min_cowboys) %
(min_horses * legs_horses) == 0)
{
cowboys = index * min_cowboys;
horses = 0;
cout <<setw(COL_WIDTH)<<cowboys;
cout <<setw(COL_WIDTH)<<horses<<endl;
}
else if ((legs - index * legs_cowboys * min_cowboys) %
(min_horses * legs_horses) != 0);
{
cowboys = index * min_cowboys;
horses = ((legs - index * legs_cowboys *
min_cowboys) %
(min_horses * legs_horses));
cout <<setw(COL_WIDTH)<<cowboys;
cout <<setw(COL_WIDTH)<<horses;
}
}
}
}
return;
}

This calculation section is a variation of a snippet that a computer
programming friend of mine sent me. His didn't work at all (yet) and
this works but with the incorrect output. Looking at the code, I see
what it's doing, but I can't completely tell that it's doing it
correctly...I'm not a math wiz! Heck, I'm a pre-seminary student that
knows a little about computers and wanted to try programming.

If someone can simply tell me what i'm doing wrong. Once I see my
error i'll learn a lot more than playing guessing games. Thanks! (by
the way this is all there is for the calculation section. The
variables you see that arent defined are defined at globals in the
beginning of the program....

// Global Constants
const int min_cowboys = 3; // The minimum number of cowboys
const int min_horses = 8; // The minimum numbner of horses
const int legs_cowboys = 2; // The number of legs each cowboy has
const int legs_horses = 4; // The number of legs each horse has
const int COL_WIDTH = 10; // Column Width

Oct 13 '06 #1
3 1541
Petrakid wrote:
for (index = min_cowboys; index < legs; index ++)
OK, index is a count of cowboys and not less than the given minimum.
min_cowboys has done its work and doesn't need to be referenced
again. Stop multiplying it into all the subsequent computations!
else if ((legs - index * legs_cowboys * min_cowboys) %
(min_horses * legs_horses) != 0);
Ignoring min_cowboys and min_horses, this checks that the legs left
over after the assumed number of cowboys will make an integral
number of horses, with none left over (remainder == 0). If != 0
then the assumption is bad and nothing should be counted/printed
for this case.

Note the semicolon hidden at the end of the line. That ends the
condition statement, so the next line (which prints something) will
always be executed.
I'm not a math wiz!
Don't let yourself panic and shut down your brain; that's a reflex
conditioned into most of us by really bad teachers. Math is just
common sense, even if you pursue it into concepts with no real-world
counterparts.
Oct 13 '06 #2
On 12 Oct 2006 20:51:48 -0700 in comp.lang.c++, "Petrakid"
<pe******@gmail.comwrote,
>Ok i understand your frustration - but I too am quite frustrated. This
assignment was due yesterday, and i am still not getting the right
calculations.
OK, I quit reading the other thread after it looked like you were
just going to beat around the bush and not post any code. so I
haven't seen your code before. And now I see it, and this is the
kind of code, pardon me, that just makes me go crazy.
>Looking at the code, I see what it's doing, but I can't completely
tell that it's doing it correctly...
And that's what I'm talking about. And in fact, you say it isn't
doing it correctly, and it's probably not obvious why to anybody.
You have to break code up into chunks simple enough that you can
understand them. You have to build a piece of the solution, and
make sure it's right, before adding another piece.

So now, while I am still crazy, I'll post an example for you.
Warning, this is untested and off the top of my head, so it may
still be wrong -- but if it's wrong, I think it's simple enough for
you to figure out where it went wrong by following the logic and
printing out the named intermediate variables.

I'd approach things something more like this:

// one ranch = three cowboys. A ranch has 6 legs.
// one herd = four horses. A herd has 32 legs.

for (int legs = min; legs <= max; legs++)
{
for (int herds = 1; (herds*32 < legs); ++herds)
{
int horse_legs = herds*32;
int cowboy_legs = legs - horse_legs;
int ranches = cowboy_legs/6;

if (legs == ranches*6 + herds*32) {
// we have a winner
}
}
}
Oct 13 '06 #3
Petrakid posted:
Ok i understand your frustration - but I too am quite frustrated.

I'm having a nice day.

This assignment was due yesterday, and i am still not getting the right
calculations.

Unfortunate circumstance.

I said "pigs and chickens" because they are barn animals,

I thought you said them because they were carbon-based life-forms -- forgive
my ignorance.

and that is really all the program requires.

If you say so.

An animal with 2 legs

A human! Wow, that was easy!

(Unless of course you don't count a human as an animal; in which case I
nominate chicken).

and one with four.

Dog!

I changed it to cowboys and horses because it seemed
more...i dunno...realistic??

I think beer bottles are more realistic than cowboys, and that tubes of PVA
glue are more realistic than horses.

Anyways, short of the right numbers printing out, I got the program
working flawlessly.

Short of becoming president, my presendential campaign worked flawlessly!

The calculation section looks like:

<snip code>

Sorry, you come across as a four year old... can't bring myself to read
through your code.

This calculation section is a variation of a snippet that a computer
programming friend of mine sent me. His didn't work at all (yet) and
this works but with the incorrect output.

My microwave works, except its output is cold.

Looking at the code, I see what it's doing, but I can't completely tell
that it's doing it correctly...I'm not a math wiz!

Study computer programming... it might come in handy!

Heck, I'm a pre-seminary student that knows a little about computers and
wanted to try programming.

Why the defeatist attitude? There has been ten year old expert C++
programmers.

If someone can simply tell me what i'm doing wrong.

Talking.

Once I see my error i'll learn a lot more than playing guessing games.
Thanks! (by the way this is all there is for the calculation section.
The variables you see that arent defined are defined at globals in the
beginning of the program....

// Global Constants
const int min_cowboys = 3; // The minimum number of cowboys
const int min_horses = 8; // The minimum numbner of horses
const int legs_cowboys = 2; // The number of legs each cowboy has
const int legs_horses = 4; // The number of legs each horse has
const int COL_WIDTH = 10; // Column Width

May I suggest you spend less money on pot, and more money on books? Or how
about you get your books from the library, and spend your money on shiny
things.

--

Frederick Gotham
Oct 13 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Vani Murarka | last post by:
Hi Everyone, Does .NET offer any collection class which will give me objects last *accessed* such that I may build a least-recently-used cache that kills off objects that haven't been used for...
6
by: pg | last post by:
Is there any simple way to query the most recent time of "changes" made to a table? I'm accessing my database with ODBC to a remote site thru internet. I want to eliminate some DUPLICATE long...
3
by: t2581 | last post by:
Hi , I run restore with rollforward In job in output, last commited transaction time less then backup image time Is it normal ? RESTORE DATABASE PRICE_V8 FROM "E:\BACKUP" TAKEN AT...
3
by: yxq | last post by:
Hello, The XP Desktop clean wizard can get the last access time of desktop shortcut, i found that the info come from ...
161
by: Dan Lenski | last post by:
Hi all, I'm a recent, belated convert from Perl. I work in a physics lab and have been using Python to automate a lot of measurement equipment lately. It works fabulously for this purpose. ...
0
by: TONY_GAL | last post by:
Tony Nottingham England 21 February 2007 TO: All People Who Care I am a private individual posting this message to help Laboratory Animals and us all. I apologize if this seems
9
by: mazen.s.m | last post by:
I have been trying to find a way to get the Domain and UserName of the user that last modified a file. I know how to get the owner of the file via WMI or Win32, but I can't find a way to get the...
0
by: TONY | last post by:
Tony Nottingham England 9 March 2007 TO: All People Who Care A new European Chemical Testing Policy called REACH has now been finalised by the European
0
by: aw | last post by:
Hello, I am a psychology student at University of Chicago conducting a survey on animals, technology, and nature. It takes only 5-10 minutes to complete and every 20th participant will be...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.