Arrays and Vectors
Dec 1, 2011 at 11:24am UTC
I'm keep on getting an error saying there's an unresolved external. What I have to do for the program is take a certain amount of values and take the difference of the sum of the values and the minimum value. Can someone please help?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
#include <iostream>
#include <vector>
using namespace std;
vector<double > read_inputs()
{
vector<double > result;
cout << "Please enter values, Q to quit: " << endl;
bool more = true ;
while (more)
{
double input;
cin >> input;
if (cin.fail())
{
more = false ;
}
else
{
result.push_back(input);
}
}
return result;
}
double minimum(vector<double > data)
{
double smallest = data[0];
for (int i=1; i < data.size(); i++)
{
if (data[i] < smallest)
{
smallest = data[i];
}
}
return smallest;
}
double sum(vector<double > data)
{
for (int i=0; i < size; i++)
{
total= total + data[i];
}
return total;
}
int main()
{
vector<double > scores= read_inputs();
if (scores.size() == 0)
{
cout<< "At least one score is required. " << endl;
}
else
{
double total = sum(scores-minimum);
cout << "Final score: " << total << endl;
}
return 0;
}
Last edited on Dec 1, 2011 at 11:27am UTC
Dec 1, 2011 at 12:24pm UTC
gcc error messages:
prog.cpp: In function ‘double sum(std::vector<double, std::allocator<double> >)’:
prog.cpp:41: error: ‘size’ was not declared in this scope
This should be data.size()
prog.cpp:43: error: ‘total’ was not declared in this scope
prog.cpp:45: error: ‘total’ was not declared in this scope
You need to add "int total;" at the beginning of sum().
prog.cpp: In function ‘int main()’:
prog.cpp:57: error: no match for ‘operator-’ in ‘scores - minimum’
scores is a vector, minimum is a function. How do you expect to subtract one from another?
Topic archived. No new replies allowed.