I am have some really weird iostream errors. This is my first time using functions. Maybe I did something completely wrong. I just need someone to point out my error and maybe help with building a function to find the minimum value out of 4 input numbers.

``````#include <iostream>
using namespace std;

double sum_funk(float n1, float n2, float n3, float n4);
//Calulates sum of the four user inputs.
double pro_funk(float n1, float n2, float n3, float n4);
//Multiplies all of the numbers together.
double max_funk(float n1, float n2, float n3, float n4);
//Determines the maximum number out of the four.
double min_funk(float n1, float n2, float n3, float n4);
//Determines the minimum number out of the four.
double avg_funk(float n1, float n2, float n3, float n4);
//Computes the average value of the four numbers.

int main()
{

float n1,n2,n3,n4,sum,product,max_num,min_num,average;
char quitentry;

cout<< "Welcome!\n";
do
{
cout<< "Please input four numbers with a space\n";
cout<< "between each entry before hitting enter: \n";
cin>> n1>> n2 >> n3 >> n4 >> endl;

sum = sum_funk(n1,n2,n3,n4);

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

cout<< "The sum of the numbers entered is equal to ";
cout<< sum << "." << endl;

product = pro_funk(n1,n2,n3,n4);
cout<< "The product of the numbers entered is equal to ";
cout<< product << "." << endl;

max_num = max_funk(n1,n2,n3,n4);
cout<< "The maximum number entered is ";
cout<< max_num << "." << endl;

min_num = min_funk(n1,n2,n3,n4);
cout<< "The minimum number entered is ";
cout<< min_num << "." << endl;

average = avg_funk(n1,n2,n3,n4);
cout<< "The average of the numbers entered is equal to ";
cout<< average << "." << endl;

cout<< "Would you like to run some new numbers \n";
cout<< "If so press anything key to continue or q to quit.\n";
cin>> quitentry;
if (quitentry == 'q')
cout<< "Have a greeeaaattttttt day tiger!";
}while(quitentry != 'q');

return 0;
}

sum_funk(n1,n2,n3,n4)
//I chose to leave out the functions because it would be too long. But if you need them let me know.``````
3
Contributors
10
Replies
11
Views
7 Years
Discussion Span
Last Post by BlueZephyr

O.K...What weird errors. Could you post them?

It goes on and on like this for about 50 lines when I try to compile.

error: no match for 'operator>>' in '((std::basic_istream<char>::__istream_type*)((std::basic_istream<char>::__istream_type*)((std::basic_istream<char>::__istream_type*)std::cin.std::basic_istream<_CharT, _Traits>::operator>> [with _CharT = char, _Traits = std::char_traits<char>, std::basic_istream<_CharT, _Traits>::__istream_type = std::basic_istream<char>](((float&)(& n1))))->std::basic_istream<_CharT, _Traits>::operator>> [with _CharT = char, _Traits = std::char_traits<char>, std::basic_istream<_CharT, _Traits>::__istream_type = std::basic_istream<char>](((float&)(& n2))))->std::basic_istream<_CharT, _Traits>::operator>> [with _CharT = char, _Traits = std::char_traits<char>, std::basic_istream<_CharT, _Traits>::__istream_type = std::basic_istream<char>](((float&)(& n3))))->std::basic_istream<_CharT, _Traits>::operator>> [with _CharT = char, _Traits = std::char_traits<char>, std::basic_istream<_CharT, _Traits>::__istream_type = std::basic_istream<char>](((float&)(& n4))) >> std::endl'
istream:120:7: note: candidates are: std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(std::basic_istream<_CharT, _Traits>::__istream_type& (*)(std::basic_istream<_Char

Look at this line

``cin>> n1>> n2 >> n3 >> n4;// >> endl;``

Notice what I remarked out.

That helped a lot but for curiosity's sake why can't I have the endl there?

And I have another question; I am given the errors below when I put in all of my functions. What am I doing wrong with the syntax?

``````sum_funk(n1,n2,n3,n4)
{
double fsum;
fsum = n1 + n2 + n3 + n4;

return fsum;
}``````

Project 4.cpp:71:9: error: expected constructor, destructor, or type conversion before '(' token
Project 4.cpp:79:9: error: expected constructor, destructor, or type conversion before '(' token

Your function needs a return type.

``````double sum_funk(n1,n2,n3,n4)
{}``````

endl is a stream manipulator not a variable.

Edited by gerard4143: n/a

Your function needs a return type.

``````double sum_funk(n1,n2,n3,n4)
{}``````

endl is a stream manipulator not a variable.

Wouldn't that be like declaring the function twice?

no its not.
and redeclaring the arguments with data types is also a good practice.

I actually get more errors when I put a data type in front of my functions. Am I not understanding it correctly or is my code faulty to begin with?

error: 'double sum_funk' redeclared as different kind of symbol
11:8: error: previous declaration of 'double sum_funk(float, float, float, float)'
71:17: error: 'n1' was not declared in this scope
71:20: error: 'n2' was not declared in this scope
71:23: error: 'n3' was not declared in this scope
71:26: error: 'n4' was not declared in this scope

Never mind I fixed that issue now I am just having trouble looping it.

Never mind I fixed the loop issue now I just need to determine how to find the max and min value using a function.