Reputation: 93
I know that this question has been posted elsewhere, and I've tried those solutions, but I get the error LNK1561 and have no clue where it is causing a problem. This program calculates and prints the largest, smallest, average, and sum of a sequence of numbers the user enters. Any questions or if you need more info, ask.
#include <iostream>
#include <climits>
using namespace std;
template <class T>
T dataSet(T &sum, T &largest, T &smallest, T avg);
template <class T>
int main(){
cout << "This program calculates and prints the largest, smallest,"
<< endl << "average, and sum of a sequence of numbers the user enters." << endl;
T avg, sum, largest, smallest;
avg = dataSet(&sum, &largest, &smallest, avg);
cout << "The largest of the sequence you entered is: " << largest << endl;
cout << "The smallest of the sequence you entered is: " << smallest << endl;
cout << "The sum of the sequence you entered is: " << largest << endl;
cout << "The average of the sequence you entered is: " << avg << endl;
return 0;
}
template <class T>
T dataSet(T &sum, T &largest, T &smallest, T avg){
T num;
signed long long int max = LLONG_MIN, min = LLONG_MAX;
int count;
do{
cout << "Enter a sequence of numbers: (^Z to quit) ";
cin >> num;
if(cin.good()){
count++;
sum += num;
if(num > max)
max = num;
if(num < min)
min = num
}
else if(!cin.good()){
cout << "Error. Try Again.";
}
}while(!cin.eof());
avg = sum / count;
return avg;
}
Upvotes: 0
Views: 1083
Reputation: 34803
main()
can‘t be a template. You‘ll have to drop the template <class T>
line before it, and instantiate the dataSet
using a specific type such as double
, for example:
// No template <class T line>
int main(){
cout << "This program calculates and prints the largest, smallest,"
<< endl << "average, and sum of a sequence of numbers the user enters." << endl;
double avg, sum, largest, smallest;
avg = dataSet(sum, largest, smallest, avg);
…
Upvotes: 1