I am trying to complete some math tutorials, and wanted to write an
answer generator in C.
The type of question is;
"A doll costs $20, a toy car costs $6, a yoyo costs $1.
What combination of toys will allow you to by 100 toys for $200?"
So far I have:
#include <stdio.h>
#define DOLL 20
#define CAR 6
#define YOYO 1
#define TOTALCASH 200
#define TOTALNUM 100
void main (void)
{
int cost;
int numb_tops;
int numb_dolls;
int numb_cars;
printf("A doll costs $%i.00, a car costs $%i.00, and a yoyo costs
$%i.00\n", DOLL, CAR, YOYO);
printf("With $%i.00 dollars you can buy %i toys, \nif you buy the
following;\n", TOTALC, TOTALN);
for(cost = 0; numbert < TOTALN & cost < TOTALC; )
}
But I cannot figure out the loops needed to compute the answer.
I am looking to make this into a function to be called when a system
of equations needs to be solved.
Thanks 9 1567
"claymic" <cl*****@cmccommunications.net> wrote in message
news:26**************************@posting.google.c om... I am trying to complete some math tutorials, and wanted to write an answer generator in C.
The type of question is;
"A doll costs $20, a toy car costs $6, a yoyo costs $1. What combination of toys will allow you to by 100 toys for $200?"
So far I have:
#include <stdio.h> #define DOLL 20 #define CAR 6 #define YOYO 1 #define TOTALCASH 200 #define TOTALNUM 100 void main (void) { int cost; int numb_tops; int numb_dolls; int numb_cars;
printf("A doll costs $%i.00, a car costs $%i.00, and a yoyo costs $%i.00\n", DOLL, CAR, YOYO); printf("With $%i.00 dollars you can buy %i toys, \nif you buy the following;\n", TOTALC, TOTALN); for(cost = 0; numbert < TOTALN & cost < TOTALC; ) }
But I cannot figure out the loops needed to compute the answer.
I am looking to make this into a function to be called when a system of equations needs to be solved.
Thanks
Any program does what you tell it to do... so as a programmer...
you gotta figure out how the problem is solved in your head first...
so i suggest you take out a piece of paper...
do this as a math word problem... then write the program according to what
you have done on the paper...
this is called "design" or "planning"...
:)

{ Kelvin@!!! }
claymic <cl*****@cmccommunications.net> wrote:
: I am trying to complete some math tutorials, and wanted to write an
: answer generator in C.
: The type of question is;
: "A doll costs $20, a toy car costs $6, a yoyo costs $1.
: What combination of toys will allow you to by 100 toys for $200?"
: So far I have:
: #include <stdio.h>
: #define DOLL 20
: #define CAR 6
: #define YOYO 1
: #define TOTALCASH 200
: #define TOTALNUM 100
: void main (void)
: {
: int cost;
: int numb_tops;
: int numb_dolls;
: int numb_cars;
:
: printf("A doll costs $%i.00, a car costs $%i.00, and a yoyo costs
: $%i.00\n", DOLL, CAR, YOYO);
: printf("With $%i.00 dollars you can buy %i toys, \nif you buy the
: following;\n", TOTALC, TOTALN);
: for(cost = 0; numbert < TOTALN & cost < TOTALC; )
: }
Since this is a _math_ problem, try couching it in mathematical terms.
E.g.:
find nonnegative integers m,n,p to satisfy:
m*DOLL + n*CAR + p*YOYO = 200 dollars,
subject to the constraint that: m + n + p = 100 toys.
That should get you started.
Wendy E. McCaughrin writes: claymic <cl*****@cmccommunications.net> wrote: : I am trying to complete some math tutorials, and wanted to write an : answer generator in C.
: The type of question is;
: "A doll costs $20, a toy car costs $6, a yoyo costs $1. : What combination of toys will allow you to by 100 toys for $200?"
: So far I have:
: #include <stdio.h> : #define DOLL 20 : #define CAR 6 : #define YOYO 1 : #define TOTALCASH 200 : #define TOTALNUM 100 : void main (void) : { : int cost; : int numb_tops; : int numb_dolls; : int numb_cars; : : printf("A doll costs $%i.00, a car costs $%i.00, and a yoyo
costs : $%i.00\n", DOLL, CAR, YOYO); : printf("With $%i.00 dollars you can buy %i toys, \nif you buy
the : following;\n", TOTALC, TOTALN); : for(cost = 0; numbert < TOTALN & cost < TOTALC; ) : }
Since this is a _math_ problem, try couching it in mathematical terms. E.g.: find nonnegative integers m,n,p to satisfy: m*DOLL + n*CAR + p*YOYO = 200 dollars, subject to the constraint that: m + n + p = 100 toys. That should get you started.
Get you started on what? I see two equations and three unknowns.
I suggest three nested for loops. As a wild guess, 0 dolls, 20 cars and 80
yoyo's might work. Also 5, 1, and 94.
But that is the easy part. The "system of equations" part sounds more
difficult. I don't know what you want there but it sounds like a pretty
impressive end product.
claymic wrote: "A doll costs $20, a toy car costs $6, a yoyo costs $1. What combination of toys will allow you to by 100 toys for $200?"
dolls + cars + yoyos = 100 ==> yoyos = 100  dolls  cars
$200 = $20*dolls + $6*cars + $1*yoyos
= $20*dolls + $6*cars + $1*(100  dolls  cars)
= $19*dolls + $5*cars + $100
$100 = $19*dolls + $5*cars
so you can buy 5 dolls, 1 car and 94 yoyos.
E. Robert Tisdale wrote: claymic wrote:
"A doll costs $20, a toy car costs $6, a yoyo costs $1. What combination of toys will allow you to by 100 toys for $200?"
dolls + cars + yoyos = 100 ==> yoyos = 100  dolls  cars
$200 = $20*dolls + $6*cars + $1*yoyos = $20*dolls + $6*cars + $1*(100  dolls  cars) = $19*dolls + $5*cars + $100
$100 = $19*dolls + $5*cars
so you can buy 5 dolls, 1 car and 94 yoyos.
Oops!! It's been a while since I was in school.
"E. Robert Tisdale" <E.**************@jpl.nasa.gov> wrote in message news:<40**************@jpl.nasa.gov>... claymic wrote:
"A doll costs $20, a toy car costs $6, a yoyo costs $1. What combination of toys will allow you to by 100 toys for $200?"
dolls + cars + yoyos = 100 ==> yoyos = 100  dolls  cars
$200 = $20*dolls + $6*cars + $1*yoyos = $20*dolls + $6*cars + $1*(100  dolls  cars) = $19*dolls + $5*cars + $100
$100 = $19*dolls + $5*cars
so you can buy 5 dolls, 1 car and 94 yoyos.
or... no dolls, 20 cars and 80 yoyos.

Peter
here is a start:
int main()
{
int ndoll = 0;
int ncar = 0;
int nyoyo = 0;
int tcash = 200;
int ttoys = 100;
int pdoll = 20;
int pcar = 6;
int pyoyo = 1;
printf("A doll costs $%i.00,
a car costs $%i.00,
and a yoyo costs $%i.00\n", pdoll, pcar, pyoyo);
while(ttoys <= 100 && tcash <= 200){
ttoys = ndoll + ncar + nyoyo;
tcash =(pdoll *ndoll) + (pcar *ncar) + (pdoll *nyoyo);
}
printf("With $%i.00 dollars you can buy %i toys,
\nif you buy the following;\n", TOTALC, TOTALN);
return(0);
}
On 10 May 2004 16:32:55 0700, cl*****@cmccommunications.net (claymic)
wrote: I am trying to complete some math tutorials, and wanted to write an answer generator in C.
The type of question is;
"A doll costs $20, a toy car costs $6, a yoyo costs $1. What combination of toys will allow you to by 100 toys for $200?"
x=doll y=toy_car z=yoyo
/
x + y + z = 100
20*x + 6*y + z= 200
\
z = 100  x  y
20*x + 6*y + 100  x  y = 200
19x + 5y = 100
19x = 100  5y
x, y unsigned
y=0 => no
y=1 => 100  5 = 95 = 5*19 #ok# => y=1, x=5, z=10051=94
#include <stdio.h>
int main(void)
{unsigned x, y, z, t;
y=0;
while((t = 5*y)<=100)
{if((100  t)%19 == 0)
{x = (100  t) / 19; z = 100  x  y;
printf("\aHo trovato la soluzione: "
"doll=%u toy_car=%u yoyo=%u\n", x, y, z);
}
++y;
}
printf("y==%u\n", y);
return 0;
}
So far I have:
#include <stdio.h> #define DOLL 20 #define CAR 6 #define YOYO 1 #define TOTALCASH 200 #define TOTALNUM 100 void main (void) { int cost; int numb_tops; int numb_dolls; int numb_cars;
printf("A doll costs $%i.00, a car costs $%i.00, and a yoyo costs $%i.00\n", DOLL, CAR, YOYO); printf("With $%i.00 dollars you can buy %i toys, \nif you buy the following;\n", TOTALC, TOTALN); for(cost = 0; numbert < TOTALN & cost < TOTALC; ) }
But I cannot figure out the loops needed to compute the answer.
I am looking to make this into a function to be called when a system of equations needs to be solved.
Thanks This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: BVM 
last post by:
Hi, All:
I have this error. It seems execution time is too long. Actually the execution time is about 30 seconds(I tested in Query analyzer). How do I solve this problem?
...

by: Alex 
last post by:
Hi, I have a problem involving some design issue.
I have two unrelated (that is, they do not derive from the same base)
classes:
ClassA
ClassB
Both have a quite similar interface, so they can...

by: Shapper 
last post by:
Hello,
I have an ASP:ImageButton where I want to call a function and pass a
string:
OnClick="Change_Photo("John")"
I am having problems with "".
I tried

by: Federico 
last post by:
Hi, this is what I can do:
 Create new solutions using VS.Net ASP.Net
 Save the solutions, build the solution, view in browser with the
solution still open.
But, once I close the solution, I...

by: Jitesh 
last post by:
I am facing a problem in webservice, I want to know what will be the exact
procedure to solve the problem.............
What I want to do............
I have a table named order in SQL Server....

by: John Salerno 
last post by:
Ok, here's a problem I've sort of assigned to myself for fun, but it's
turning out to be quite a pain to wrap my mind around. It's from a
puzzle game. It will help if you look at this image:
...

by: vj 
last post by:
Hi all,
I want to solve the two equations
u*tan(u)=w
and
u^2 + w^2=V^2, where V is a known constant, and u and w are the two
unknowns to be determined. Please can someone suggest me how to...

by: arun 
last post by:
Query is too complex

Hi, I was trying to solve this problem since last two days but couldn't
find any solution.
...

by: Michael Reichenbach 
last post by:
Here is the example code.
int main(int argc, char *argv)
{
string Result;
WIN32_FIND_DATA daten;
HANDLE h = FindFirstFile(TEXT("c://test"), &daten);
system("PAUSE");
return EXIT_SUCCESS;
}

by: itsvineeth209 
last post by:
My task is to create login control without using login control in tools. I shouldnt use sqldatasource or any other. I should use only data sets, data adapters and data readers etc.
U had created...

by: isladogs 
last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, Mike...

by: veera ravala 
last post by:
ServiceNow is a powerful cloudbased platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...

by: mar23 
last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...

by: jimatqsi 
last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...

by: isladogs 
last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM).
In this month's session, the creator of the excellent VBE...

by: fareedcanada 
last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...

by: stefan129 
last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multidomain SSL certificates? Any recommendations on reliable providers or specific...

by: davi5007 
last post by:
Hi,
Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...

by: MeoLessi9 
last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
  