### Need help with C++ task Hello.
I've come across some difficulties doing my C++ task.
I'm not sure how can I write a reference to a function. Would appreciate any help.
Here is the photo of the task: https://prnt.sc/y1i40V7XFe-G (there might be some grammatical mistakes since I was translating it myself)

P.S sorry if there are any illogical mistakes or stuff like that. I'm still very new to this and still learning.

#include <iostream>
#include <iomanip>
#include <cmath>
#include <fstream>
using namespace std;
//----------------------------------
void Read(int &n, char type[], int kg[], double price[]);
int Quantity(int n, int kg[]);
double Sum(int n, int kg[], double price[]);
void Writing(int n, char type[], int kg[], double price[]);
int main ()
{
int n, type, kg;
double price;

Writing(n, type, kg, price);

return 0;
}
void Read(int &n, char type[], int kg[], double price[])
{
ifstream df("duom.txt");

df >> n;
for(int i = 0; i < n; i++)
df >> type[i] >> kg[i] >> price[i];
}
int Quantity(int n, int kg[])
{
int S;

for(i = 0; i < n; i ++) S+=kg[i];

return S;
}
double Sum(int n, int kg[], double price[])
{
double price;

for(i = 0; i < n; i ++) price = kg[i] * price[i];

return price;
}
void Writing(int n, char type[], int kg[], double price[])
{
ofstream rf("rez.txt");

rf << "Cheries:" << endl;
rf << "Sold, kg: " << Quantity(n, kg) << endl;
rf << "For amount of money: " << Sum(n, kg, price)
rf << "Average price per kilogram, Eur: " << Sum(n, kg) / Quantity(n, kg) << endl;

rf << "Plums:" << endl;
rf << "Sold, kg: " << Quantity(n, kg) << endl;
rf << "For amount of money: " << Sum(n, kg, price)
rf << "Average price per kilogram, Eur: " << Sum(n, kg) / Quantity(n, kg) << endl;

rf << "Apples:" << endl;
rf << "Sold, kg: " << Quantity(n, kg) << endl;
rf << "For amount of money: " << Sum(n, kg, price)
rf << "Average price per kilogram, Eur: " << Sum(n, kg) / Quantity(n, kg) << endl;

rf << "Pears:" << endl;
rf << "Sold, kg: " << Quantity(n, kg) << endl;
rf << "For amount of money: " << Sum(n, kg, price)
rf << "Average price per kilogram, Eur: " << Sum(n, kg) / Quantity(n, kg) << endl;

rf << "All fruits:" << endl;
rf << "Sold, kg: " << Quantity(n, kg) << endl;
rf << "For amount of money: " << Sum(n, kg, price)
rf << "Average price per kilogram, Eur: " << Sum(n, kg) / Quantity(n, kg) << endl;
} if you translated it right, reference does not mean c++ reference, but english reference.
that is, just use the functions in your code.

main()
{
cout << Sum(...parameters..); //this is a 'reference' to Sum in 'english'.
}

you can make a function pointer that is sort of like a reference to a function, and the name of a function, much like the name of an array, can collapse to a pointer, but I do not believe the assignment is asking for these things, and they are a little advanced in both syntax and knowing when to use them (advanced compared to what you appear to be doing)
Topic archived. No new replies allowed.