Of course you will have to find the lowest number. Let's say that you found the lowest number to be 5. Then go ahead and add up all 10 numbers and then subtract 5.

So how do you find the lowest number? I probably should let you figure that out yourself but learn something from what I show you here so this isn't in vain : )

#include<iostream>

using namespace std;

int main()

{

int arr[10] = { 1,2,3,4,5,6,7,8,9,10 };

int temp = 0;

temp = arr[0] < arr[1] ? arr[0] : arr[1];

for(int i = 2; i < 10; ++i)

temp = temp < arr[i] ? temp : arr[i];

cout << "\nThe lowest number is " << temp << endl;

return 0;

}

You can copy and paste that code right into your IDE's editor and it should run. You can experiment with this to see how it works in finding the lowest number.

Here is a very common construct of statements that are very frequently used in programming:

if(arr[0] < arr[1])

temp = arr[0]

else

temp = arr[1];

We can see that the variable temp will take on the value of either arr[0] or arr[1] all depending on the truth or falsehood of this statement: arr[0] < arr[1]; If the statement is true, temp gets arr[0]. If it's false temp will get arr[1]; This is called a conditional statement because the value temp will get is conditional on the truth or falsehood of the statement made. Because this is used so much, they came up with a condensed version of it so it all fits on one line of code like so:

temp = arr[0] < arr[1] ? arr[0] : arr[1];

It's called the ternary operator ?. There are two values separated by a colon at the end like this arr[0] : arr[1]. Temp will get the value on the left of the colon if the statement is true or else it will get the value on the right of the colon if the statement is false. The statement appears before the question mark and the question mark is asking "What's the deal? Is this statement true or false? And that determines what value temp gets, the first one or the second one. This is the exact same thing as the 4 lines of code for the if - else construct above just a shortened version of it. Here again is the ternary operator:

x = statement ? y : z

In the code I provided, the for loop starts i out at 2 since the first two elements of the array (arr[0] and arr[1]) have already been worked and the lowest of the two is in temp.