dynamically allocated arrays

S

SneakyElf

hi all, im super new with c++ (and no background in programming
whatsoever!)
i have a task to make functions to calculate total profit and the
average number of things sold. data is read from a file. my problem is
with functions, namely setting up parameters and later calling
functions in the main().

here are the two functions (?) that i wrote so far, one is supposed to
get total profit and the other calculate average

#include <iostream>
#include <fstream>
#include <vector>
using std::ifstream;
using namespace std;

double getTotalProfit (double totalProfitOrder, float
profitLossForFreeCookies ) { // what do I set as parameters in this
function?
int freeCookies = 5;
float cookieProductionCost = 0.10;
float profitLossForFreeCookies = freeCookies * cookieProductionCost;
double totalProfitPerOrder = cookiesSoldPerOrder * cookiePrice -
profitLossForFreeCookies;
return totalProfitOrder;
}


double avgNumOfCookiesSold (double avgOfCookieSales, int
cookieOrderCount) {
double avgOfCookieSales;
int totalCookiesOrdered = 0;
int cookieOrderCount = 0;
cookieOrderCount ++;
inData >> cookiesSoldPerOrder;
totalCookiesOrdered += CookiesSoldPerOrder;
avgOfCookieSales = totalCookiesOrdered/cookieOrderCount;
return avgOfCookieSales;
}

i realize my parameters are screwed up, but if you could show me what
i am doing wrong i'd appreciate it.

(for the average i plan on using vectors and dynamically allocated
arrays, but i have trouble setting those up as well - its a mess
really!, however, the setting up functions and calling them is giving
me the most trouble)

any help is greatly appreciated!
 
O

Obnoxious User

(e-mail address removed) skrev:
hi all, im super new with c++ (and no background in programming
whatsoever!)
i have a task to make functions to calculate total profit and the
average number of things sold. data is read from a file. my problem is
with functions, namely setting up parameters and later calling
functions in the main().

here are the two functions (?) that i wrote so far, one is supposed to
get total profit and the other calculate average

#include <iostream>
#include <fstream>
#include <vector>
using std::ifstream;
using namespace std;

double getTotalProfit (double totalProfitOrder, float
profitLossForFreeCookies ) { // what do I set as parameters in this
function?
int freeCookies = 5;
float cookieProductionCost = 0.10;
float profitLossForFreeCookies = freeCookies * cookieProductionCost;

profitLossForFreeCookies = freeCookies * cookieProductionCost;
double totalProfitPerOrder = cookiesSoldPerOrder * cookiePrice -
profitLossForFreeCookies;

totalProfitPerOrder = cookiesSoldPerOrder * cookiePrice -
profitLossForFreeCookies;
return totalProfitOrder;
}


double avgNumOfCookiesSold (double avgOfCookieSales, int
cookieOrderCount) {
double avgOfCookieSales;

^^Redeclaration of parameter. Remove.
int totalCookiesOrdered = 0;
int cookieOrderCount = 0;

^^Redeclaration of parameter. Remove.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top