3 Replies - 807 Views - Last Post: 16 May 2008 - 11:21 AM Rate Topic: -----

#1 gaz3787  Icon User is offline

  • New D.I.C Head

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

A little help on my code for a minimization programme

Post icon  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  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 12
  • View blog
  • 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
Was This Post Helpful? 0
  • +
  • -

#3 Codegamer  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • 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 :crazy:
Was This Post Helpful? 0
  • +
  • -

#4 gabehabe  Icon User is offline

  • GabehabeSwamp
  • member icon




Reputation: 1430
  • View blog
  • 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 :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1