+ 1

Finding a minimum in C++ without an array?

If anyone can help me out, that would be great! I'm currently working on a program in C++ where I have to find the average of x scores declared by the user, with the lowest score drop. I'm not allowed to use arrays. I've got everything functioning just fine except for getting the lowest score. Please tell me any changes I need to make to my code: #include "stdafx.h" #include <iostream> double calcAverage(double, double); double findLowest(double, double); using namespace std; double tests, lowest; double score; double l; double sum = 0, count = 0; int x; int main() { double tests, average; cout << "How many tests will there be? "; cin >> tests; cout << "Enter "<<tests<<" scores:\n"; cin>>score; lowest = score; for (int x = 2; x <= tests; x++) { cin >> score; l = findLowest(score, lowest); sum+=score; count++; } sum -= lowest; cout<<"Lowest number is: "<<l<<endl; // cout<<"Sum is: "<<sum<<endl; double i = calcAverage(sum, count); cout<<"Average without the lowest score is: " << i <<endl; return 0; } double findLowest(double score, double lowest) { if(score < lowest) lowest = score; return score; } double calcAverage(double sum, double count) { double avg = sum / (count - 1); return avg; }

19th Oct 2017, 11:07 PM
Jack Bilsland
Jack Bilsland - avatar
6 odpowiedzi
+ 4
Okay, ao assume you have integer input cin>>i;//number of inputs int maxi; for (int k=0;k<i;k++){ cin>>m; if m>maxi{maxi=m} } I would do it this way
19th Oct 2017, 11:18 PM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 3
It is part of the loop. {These brackets enclose a loop}
19th Oct 2017, 11:28 PM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
0
shouldn't it be parenthesis, not brackets?
19th Oct 2017, 11:31 PM
Jack Bilsland
Jack Bilsland - avatar
0
o wait nvm I'm dumb lmao I see what you did
19th Oct 2017, 11:31 PM
Jack Bilsland
Jack Bilsland - avatar
0
But I'm required to use a function to obtain the min. the prompt is: "write a program to calculate the avg of a series of test scores where the lowest score is dropped. the program should ask the user how many tests there will be. use the functions findLowest & calcAverage. Do this without arrays"
19th Oct 2017, 11:34 PM
Jack Bilsland
Jack Bilsland - avatar
0
arrays
28th Oct 2017, 7:54 PM
Dmitriy Yudnikov
Dmitriy Yudnikov - avatar