what is difference between calling a function from Main function and returing value from different function to main function, you get it what l want to ask?
And how can l call this function from main function?
please help
#include<iostream>
using namespace std;
void Avg()
{
int Max_valuue;
int average=0;
int number;
int x=1;
int sum=0;
cin>>Max_valuue;
while(x<=Max_valuue)
{
cin>>number;
sum+=number;
average=sum/Max_valuue;
x++;
#include <iostream>
usingnamespace std;
double Avg()
{
int Max_valuue;
int number;
int x = 1;
double sum = 0;
cin >> Max_valuue;
while (x <= Max_valuue)
{
cin >> number;
sum += number;
x++;
}
double average = sum/Max_valuue;
return average;
}
int main()
{
double res = Avg();
cout << "Average is " << res << '\n';
}
Note: while main() is a bit special, it is not special in this. Any function can call other functions.
For example, your Avg() calls functions: cin >> Max_valuue; contains a function call, because that operator>> is actually a function. A member function of a class, for cin is an object whose type is not a primitive like char, int or double.
(There are also standalone operator>> functions, and a bitshift operator>> that is not a function.)
[EDIT]
Fascinating.
Your previous thread saw functional code http://www.cplusplus.com/forum/beginner/224759/#msg1028034
It is good that you don't blindly copy-paste.
It is not so good that your own attempts deviate quite much from examples.