// //**********************************************************************************
//File Name: averages.cc
//Description: Calculate the smallest, largest, and the average of the input values.
//Date: 10-6-09
//**********************************************************************************

#include <iostream>
#include <string>

using namespace std;

int main() {

string line;
int min=2000000;
int max=0;
double avg;
int next;
double sum = 0;
double count = 0;

cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(7);

cin>> next;

	while (!cin.eof()){
	getline(cin,line)=next;
		if (!cin.fail()) {
			if (next < min)
			min = next;
	
			if (next > max)
			max = next;
			
			count++;
			sum=sum+next;
 }
}

	avg=sum/count;
cout << min;
cout << max;
cout << avg;
 
}

i get the error:
averages.cc:30: error: no match for 'operator=' in 'std::getline [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>](((std: :basic_istream<char, std::char_traits<char> >&)(&std::cin)), ((std::basic_string<char, std::char_traits<char>, std::allocator<char> >&)(&line))) = next'/usr/sfw/lib/gcc/i386-pc-solaris2.10/3.4.3/../../../../include/c++/3.4.3/iosfwd:62: note: candidates are: std::basic_istream<char, std::char_traits<char> >&std::basic_istream<char, std::char_traits<char> >::operator=(const std::basic_istream<char, std::char_traits<char> >&)bash-3.00$

plz i need help!

Line 29 won't work. getline reads a line, so you should have this (no = sign):

getline (cin, line);

If you then want to convert line into an integer, use atoi or strtol. These work on C-style strings, not C++ style strings, so convert line using c_str ();

getline (cin, line);
next = atoi (line.c_str ());

If you then want to convert line into an integer, use atoi or strtol. These work on C-style strings, not C++ style strings, so convert line using c_str ();

Help with Code Tags
C++ Syntax (Toggle Plain Text)
getline (cin, line);
next = atoi (line.c_str ());

Disappointed to see you suggest a non-standard function.

In C++ you should use sstream for conversion from string to numbers.

#include<sstream>
//more stuff if needed
int main()
{
     stringstream ss;
     string strNum = "12345.56";
     float num= 0.0f;
     ss << strNum;   //input the string into the stream
     ss >> num;  //output the result into num = 12345.56f;
    // maybe error checking if needed.
   return 0;
}

Disappointed to see you suggest a non-standard function.

In C++ you should use sstream for conversion from string to numbers.

Or just read an integer from the cin stream in the first place.

Or just read an integer from the cin stream in the first place.

Then that would mean more probable problems.

Then that would mean more probable problems.

Not so. Extracting an integer from an strstream works exactly the same as extracting from cin, an ifstream, or any other stream.

Disappointed to see you suggest a non-standard function.

atoi is standard. itoa isn't. Someone told me strtol is better than atoi, but I can't remember the reasons given and I don't know if atoi is in fact to be avoided. Generally I use strtol. Never had a problem with either, which doesn't mean there aren't drawbacks. But atoi is standard.

atoi is standard. itoa isn't. Someone told me strtol is better than atoi, but I can't remember the reasons given and I don't know if atoi is in fact to be avoided. Generally I use strtol. Never had a problem with either, which doesn't mean there aren't drawbacks. But atoi is standard.

Oh, your right. I was thinking itoa for some reason. Anyways, here
is the reason to use strtol, Link. Its because of error checking.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.