Please help me with these simple questions

Hello,
I have a code which has issues in some parts of it.
The problematic part is:

1
2
3
4
5
6
7
 var attt = new double[countss];  
            double mymax;
            for (int count = 0; count < countss; count++)
            {
                attt[count] = neww[count] - old[count];
            }
			attt = attt[0]- mymax;  

Question1: How to express attt without having this error? can not implicitly convert type double to double? This error refers to line 7.
Question2: How to calculate this value? mymax = maximum (attt[1], attt[2], ...attt[count])? Please note that i want to subtract attt[0] from mymax that is in my first question but both if them are at the same loop. But if it can't be at the same loop, please code it somehow that it works.
Thanks in advance for your time and help.
Last edited on
can not implicitly convert type double to double

Double to double? The message probably has more than that.

subtract attt[0] from mymax
attt[0] - mymax

Who substracts from whom?

You have two lists of values, old and neww. They must have same number of elements and they must have at least one element each.

You compute elementwise difference of the two lists; a new list.

However, you apparently don't want a whole list, just the largest difference and the difference of the first pair:
auto result = neww[0] - old[0] - mymax;

How to calculate maximum(attt[1], attt[2], ...attt[count])?

Is that the maximum of whole list or does it omit the first (attt[0])?

You do look each element in turn. If its value is larger than the largest value (mymax) that you have seen so far, then you must update the mymax. When you have seen all the values, the mymax must hold the largest value of the whole list.
Let me explain more. Neww and old have functions in other parts and they work well. The thing i am looking for is it:
There is a for loop and i want to Calculate this:

attt = attt[0] - maximun(attt[1], attt[2], attt[3], attt[4], attt[5] and....)

attt[0] : is being calculated by the loop as well as attt[1], attt[2], attt[3], attt[4], attt[5] and so on. All of these variables keep double amounts.

mymax: holds the maximum value of attt[1], attt[2], attt[3], attt[4], attt[5] and....

attt: keeps the subtraction result of attt[0] and mymax. And it is defined in the first line as double.

how can i do that? If you provide me the code, that would be perfect.
Last edited on
You have attt and attt and they are entirely different. One is a double value. The other is an array of double values. One number, many numbers. Not possible. Rename one of the two.

It is apparent that you do need attt later. However, you have not stated that you would need attt for anything else than computing the attt. (Was that clear? Not ambiguous? Can you tell which attt is which? Rename one.)

You could explore with these:
http://www.cplusplus.com/reference/algorithm/transform/
http://www.cplusplus.com/reference/algorithm/max_element/
When i insert attt in another defined function like beliw, it works fine without any problem.
attt=function1(attt) ;
But when i add it to thus function, attt = attt[0]- mymax; the double to double conversion problem arises.
What should i do now to fix it? :(
Use a different variable. An array is not a number. A double is not a double*
> the double to double conversion problem
stop paraphrasing a message that you don't understand.
Lets take a step back. You wrote:
var attt = new double[countss];


What type is the var?
Topic archived. No new replies allowed.