# A little help on my code for a minimization programme

Page 1 of 1

## 3 Replies - 822 Views - Last Post: 16 May 2008 - 11:21 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=52257&amp;s=029de9363d895e1615ae7e0a0fec40fa&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 gaz3787

Reputation: 0
• Posts: 1
• Joined: 16-May 08

# A little help on my code for a minimization programme

Posted 16 May 2008 - 07:22 AM

```#include <iostream>

//int main is the main building block of the programme

int main()

{
int Y1;
int En;
int Y2;

std::cout << "Enter the value for Y1"<< std::endl;
std::cin >> Y1;

std::cout << "Enter the value for Y2"<< std::endl;
std::cin >> Y2;

std::cout << "Enter the value for En"<< std::endl;
std::cin >> En;

int testA = 1;
int testB = 1;
int A = 1;
int B = 1;
int Diff = Y1 - A - (B * En) - Y2;

int testDiff;

for(testA = 1; testA <= 101; testA++)
{
for(testB = 1; testB <= 101; testB++)
{
testDiff = Y1 - testA - (testB*En) - Y2;
if (testDiff < Diff)
{
Diff = testDiff;

A = testA;
B = testB;
}
}
}
std::cout << "the value of A is" << A << std::endl;
std::cout << "the value of B is" << B << std::endl;

return 0;

} //end of function
```

Hi, this is my code for a programme I am trying to write.

Basically we have two pieces of equipment, an old one and a new one and for the same sample, they give slightly different data. My idea is to design a programme that can look at the data of the two to see if an equation that can be formed so if i have one i can place that into the equation to get what the other would look like.

I think mine only works for intergers, but i need it to work for decimals too, also currently this only gives me the answer of 101...... for both A and B

I really need help on this as I am very new to this.

Thank you

Gareth

Is This A Good Question/Topic? 0

## Replies To: A little help on my code for a minimization programme

### #2 skater_00

• D.I.C Regular

Reputation: 12
• Posts: 256
• Joined: 30-April 08

## Re: A little help on my code for a minimization programme

Posted 16 May 2008 - 07:30 AM

Can you explain the purpose of your program a bit better? Because I don't get it, at all.. o.0

### #3 Codegamer

Reputation: 1
• Posts: 127
• Joined: 04-May 08

## Re: A little help on my code for a minimization programme

Posted 16 May 2008 - 11:14 AM

Neither do I

### #4 gabehabe

• GabehabeSwamp

Reputation: 1430
• Posts: 11,006
• Joined: 06-February 08

## Re: A little help on my code for a minimization programme

Posted 16 May 2008 - 11:21 AM

I don't understand the purpose of this program, BUT:
The reason that you have 101 for each result is that you set them to be 101. You have a loop that is executed 100 times, but at the end of your loop, you assign A to equal testA (your counter).

Why do you loop 100 times? What do you want to achieve?

As for working with decimals, why not use float type, instead of an int?

Hope this helps