I'm new to this board, and to be honest, I have been beating my head against the wall attempting to complete this last portion of this project. I got everything else working wonderfully. Long story short, I need to apply the associated string values to the variable day. Which string is based off of the data in the array "hotdogs[] and the corresponding value "largest".
"Largest" is the biggest number in the "hotdogs[]" array. My thinking of this is if array element 0 in hotdogs[] is not the largest, move onto the else if, and so on until it finds which element of array hotdogs[] is the largest variable.
The whole thing compiles and runs, but keeps giving me the same answer. That day "7" has the most sold hot dogs. Regardless of where the largest number is entered. Since I need a 10 ranking to post pics, I'll copy past the code.
for (h=0; h<=6; h++)
{
cin >> hotdogs[h];
hdogsales = hdogsales + hotdogs[h];
}
for (int h=0; h<=6; h++)
{
if(hotdogs[h] > largest)
largest=hotdogs[h];
}
{
if (hotdogs[h] == largest)
day = "1";
else if (hotdogs[h] == largest)
day = "2";
else if (hotdogs[h] == largest)
day = "3";
else if (hotdogs[h] == largest)
day = "4";
else if (hotdogs[h] == largest)
day = "5";
else if (hotdogs[h] == largest)
day = "6";
else if (hotdogs[h] == largest);
day = "7";
}
I would REALLY appreciate help on this. It is driving me nuts already. I have an inkling that the parameters I'm setting in my if statement is the culprit, but for the life of me, I cannot think what else to use in there.
largest= hotdogs[0];prior to entering the loop (and optionally start the loop at 1). As-wrtten,largestis in determine entering the loop, and thus evaluating it is undefined behavior. Andhis accesinghotdogs[]our of bounds anyway once you finish the for-loop.std::max_elementfunction that finds the max element, and the index can be extracted from the result withstd::distance.if/else ifconditions looks suspicious. The conditions are all the same.