473,414 Members | 1,636 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

dynamically allocated arrays

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!

Apr 15 '07 #1
1 1343
Sn*******@gmail.com 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.
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.
--
OU
Apr 15 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Jeff Williams | last post by:
Ok, everyone loves to talk about dynamic arrays and ptr's etc, they provide endless conversation :) so here goes: Will this leak memory (my intuition says yes): void foo(vector<int*>& vec) {...
10
by: junky_fellow | last post by:
What is the correct way of dynamically allocating a 2d array ? I am doing it the following way. Is this correct ? #include <stdlib.h> int main(void) { int (*arr)(3); arr =...
5
by: nmtoan | last post by:
Hi, I could not find any answer to this simple question of mine. Suppose I have to write a program, the main parts of it are as follows: #include <blahblah.h> struct {
37
by: yogpjosh | last post by:
Hello All, I was asked a question in an interview.. Its related to dynamically allocated and deallocated memory. eg. //start char * p = new char; ...
5
by: tricard | last post by:
Good day all, I have created a two dimensional array (matrix for my purposes) whose size is dynamically allocated. (i.e. rowSize and colSize are both taken as input, then malloc() is used to...
94
by: smnoff | last post by:
I have searched the internet for malloc and dynamic malloc; however, I still don't know or readily see what is general way to allocate memory to char * variable that I want to assign the substring...
2
by: flyvholm | last post by:
According to a couple of other threads you can't use sizeof with dynamic arrays - you'll have to keep track of the memory allocated. In my case, strings are filled into a dynamic array by a...
6
by: bwaichu | last post by:
Is my understanding of the allocation of these correct? I used fixed sized allocations for the example below, so I realize there is some optimization that can be done to those. I would like to...
7
by: Serpent | last post by:
The C-FAQ describes some techniques here: http://c-faq.com/aryptr/dynmuldimary.html I was using something slightly different from the C-FAQ and I was wondering if it was legal. Say I want a...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.