Hello, I am trying to create a template that determines missing values within a formatted array of 5 integers...for example:
int array[5] = {x, x+1, x+2, x+3, x+4};
For any given array[5], three values are known. How do I calculate the 2 missing values? Sounds like an algebra problem but I'm interested in a template because I need to fill the array with the missing values...any ideas?
Also, can I pass variables like (x+1) into an array? would that help to calculate x+1 if x is 3...?
Easy. The next elements takes the value of the previous element with the value of one added to it.
paulmcco wrote:
Also, can I pass variables like (x+1) into an array? (sic)
Yes. That's perfectly valid. It's what's known as an expression. Basically, assuming x is a pre-defined type, one is added to the value stored within x which results in n (doesn't modify the value stored within x).
paulmcco wrote:
would that help to calculate x+1 if x is 3...? (sic)
You lost me. There's a faster way to do your assignment.
1 2
for( int Counter( 0 ); Count < 5; Count++ )
array[ Counter ] = ( x + Counter );
I need to place three values into a sorted array that is formatted like this:
array[5] = {x, x+1, x+2, x+3, x+4};
...if the values are (3, 5, 7) then the array would be filled like this:
array[5] = {3, x+1, 5, x+3, 7};
because 5 = x+2, and 7 = x+4.
Next, I need to determine the missing values...I guess that's just simple algebra but the location of the missing array values is important. I could write a lot of if statements but there has to be an easier way...
hold on a minute .. if ur program is like this:
int main()
1 2 3 4 5 6 7 8 9 10 11
{
constint s=5;
int x=3;
int a[s]={x, x+1, x+2, x+3, x+4};
for(int i(0); i <s; i++)
cout <<a[i]<<endl;
system("pause");
return 0;
}
ur result would be 3 ,4 , 5, 6,7; so where is ur problem ?where is ur question?
if what i understand ..if u have a changing value ..on what it changes ?
if in the input like from the user ..put cin >> y; and value changes is y..if on calculation the result should be something like y=x+2 + 4*t; i dunno other than that ushould explane ur question