Oh dear. You should ask your school for a refund.
C Indentation
Oh dear. You should ask your school for a refund.
C Indentation
OK, now I have
So how do I fix it? I followed some of the previous posts, but it still is not giving me the correct result.Code:#include <iostream> #include <iomanip> using namespace std; int main( ) { float n; float average = 0; float o; float value = 0; float highest = 0; float lowest = 0; // cin >> o; n = 7; for (float i = 0; i < n; ++i) { highest = value; lowest = value; cin >> value; if (value > highest) { highest = value; } if (value < lowest) { lowest = value; } average += value; } if (value != highest || value != lowest) { average /= 5; } // average = average + 1; cout << "Average score: " << setprecision(3) << average; }
I suggest you add a simple print statement that prints the highest and lowest between line 31 and 33. Then reread post #15, pay particular attention to the first question: "Why do you do this everytime?"
Why just "some"?I followed some of the previous posts,
Jim
It correctly shows 9.1 as the highest, but incorrectly shows 8 as the lowest.
As for why do you do this everytime, I thought that was the way to record the highest and lowest. If I am wrong please explain why and help me get it right.
O_oWhy just "some"?
Obviously afraid of witches...
Soma
“Salem Was Wrong!” -- Pedant Necromancer
“Four isn't random!” -- Gibbering Mouther
You mean in
andCode:highest = value;
?Code:lowest = value;
If so, how else am I supposed to do it? My logic there is if a new highest is found, highest becomes that highest, and same for lowest. I must be doing it wrong somehow though.
The simplest way to do it would be to initialize these variables with INT_MIN and INT_MAX respectively.
(highest with INT_MIN , not the other way around)
You can find these macros in <limits.h>
Sorry, I can't use any other header files in my situation.
So does the first value have to be given outside the loop?