|
Corrections for the code
I find that my C++ code is not displayed correct even though my original code is correct. I modified the code again.
I tried to write a C++ code to calculate the solutions. I find that there are exactly 7 solutions. The maximam value is 1960, and all possible maximum points are (X,Y)=(28,14), (31,12), (34,10), (37,8), (40,6), (43,4), (46,2).
I give two paragraphs of code. The first one is to find the maximum value is 1960. The second one is to find all possible solutions that have value 1960.
//Code 1
#include <IOSTREAM.H>
void main()
{
int X;
int Y;
int myMax;
int tempMax;
int Xup=197; // maximum integer number of X that satisfies X+3Y<=200 (or 2X+3Y<=98) with integer Y>0
int Yup=32;// maximum integer number of Y that satisfies 2X+3Y<=98 (or X+3Y<=200) with integer X>0
for (int i=1; i<=Xup; i++)
{
for(int j=1; j<=Yup;j++)
{
if(2*i+3*j<=98 && i+3*j<=200 && i>=2*j)
{
myMax=40*i+60*j;
if(myMax>tempMax)
tempMax=myMax;
}
}
}
<TEMPMAX;< p>
// display Max as =tempMax here
}
/////////////////////////////
//Code 2
#include <IOSTREAM.H>
void main()
{
int myMax;
int Xup=197;
int Yup=32;
for (int i=1; i<=Xup; i++)
{
for(int j=1; j<=Yup;j++)
{
if(2*i+3*j<=98 && i+3*j<=200 && i>=2*j)
{
myMax=40*i+60*j;
if(myMax==1960)
{
// display i and j here
<J;<J<<ENDL;< p>}
}
}
}
} |
|