You are using a version without Ads of this website. Please, consider donating:

### help me in this ARRAY program

 ```Objective: The purpose of this project is to expose you to: One Dimensional arrays, input/output of arrays and manipulating arrays. Problem Specification: The Little League Ball Park sells Hot Dogs and Ice-cream. During the week of June 12th, the dollar sales were as follows: Day Hot Dogs Ice-cream 1 \$112 \$93 2 \$94 \$325 3 \$105 \$225 4 \$92 \$71 5 \$239 \$98 6 \$442 \$298 7 \$537 \$333 Program Requirements: a. Create separate arrays for hot dogs and ice cream by inputting the values into the arrays from the keyboard. "Do your input in main" b. Calculate the sales in dollars for the week for hot dogs and ice cream. c. Compute the grand total of sales for the week for both hot dogs and ice cream. d. Find the day and amount that the most hot dogs was sold. e. Count how many times in this week ice cream sold more than \$250 in a day. ----------- Output of the program is the following report Little League Ball Park Sales Report Week of June 12,2011 Day Hot Dogs Ice-cream --- -------- --------- 1 \$112.00 \$ 93.00 2 \$ 94.00 \$325.00 3 \$105.00 \$225.00 4 \$ 92.00 \$ 71.00 5 \$239.00 \$ 98.00 6 \$442.00 \$298.00 7 \$537.00 \$333.00 Totals \$xxx.xx \$xxx.xx Grand Total = \$xxxx.xx Day Number: # Sold the most Hot Dogs = Number of times in a week that ice cream sold more than \$250 in a day is: ------------ The Program should contain the following functions: 1. Separate functions are used to calculate total sales for the week for each item sold. 2. A function is used to find the day and amount where the most hot dogs soda is sold. 3. A function is used to count how many times in this week ice cream sold more than \$250 in a day. 4. A function is used to print the headings 5. At least one function is used to print the information. ```
 ``12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273`` ``````#include #include #include using namespace std; //Prtotype float calc_HotDogs_Total (float[] , int ); float calc_IceCream_Total (float[] , int ) ; float Grand_Total (float IceCream_Total_Sales, float HotDogs_Total_Sales ) ; int main() { const int NUM = 6; int Days[NUM] ; float HotDogs_Sales[NUM], IceCream_Sales[NUM] ; float HotDogs_Total_Sales, IceCream_Total_Sales ; HotDogs_Total_Sales = calc_HotDogs_Total( HotDogs_Sales, NUM ) ; IceCream_Total_Sales = calc_IceCream_Total( IceCream_Sales, NUM) ; for ( int i= 0; i <= NUM; i ++ ) { Days[i] ; } for ( int i = 0; i <= NUM; i ++) { cout << "please enter number of hot dogs sold:" ; cin >> HotDogs_Sales[i] ; } for ( int i = 0; i <= NUM; i ++ ) { cout << "please enter number of ice cream sold:" ; cin >> IceCream_Sales[i]; } //cout << HotDogs_Total_Sales << endl ; return 0; } float calc_HotDogs_Total( float HotDogs_Sales[], int NUM ) { float HotDogs_Total_Sales = 0 ; HotDogs_Sales ; for ( int i = 0; i <= NUM; i ++ ) { HotDogs_Total_Sales = HotDogs_Total_Sales + HotDogs_Sales[i] ; } return HotDogs_Total_Sales; } float calc_IceCream_Total (float IceCream_Sales[], int NUM) { float IceCream_Total_Sales = 0 ; IceCream_Sales; for ( int i = 0; i <= NUM; i ++) { IceCream_Total_Sales = IceCream_Total_Sales + IceCream_Sales[i] ; } return IceCream_Total_Sales; } float Grand_Total ( float IceCream_Total_Sales, float HotDogs_Total_Sales ) { float Grand_Total = IceCream_Total_Sales + HotDogs_Total_Sales ; return Grand_Total; }``````

 ```So far im correct no errors ....need help with more functions :( & also when i run it without debugging it shows error "Stack around the variable 'HotDog_Sales" umm well i know because im not finish.... PLEASE HELP ME with this program Can anyone write rest of the program for me because that's all i know so far :( ```
 Can anyone write rest of the program for me...?
No.

You shouldn'd ask people to write programs for you. It likely that this code was provided to you already and your trying to get us to do your work for you
Last edited on
No i did this by myself i just had error with one declaration and that's all i got help with ... and i dont know how to write more functions so that's y im here!!
Well that's the point of the assignment; to make you learn how to do that yourself. You can look at the tutorial on this site if you want to learn.
Where can i find the tutorial?
> it shows error "Stack around the variable 'HotDog_Sales"

The positions in a C++ array start at 0. If we have an array of size N, there are exactly N objects in the array; and they are at positions 0, 1, 2, 3, ..., N-2, N-1. The last one being at position N-1.

 ``12`` ``````const int NUM = 6; float HotDogs_Sales[NUM]``````

In this array contains NUM objects of type float;
the first one is `HotDogs_Sales[0]` and the last one is `HotDogs_Sales[NUM-1]`

This loop tries to access something that does not exist: an element at position NUM:
 ``123456`` ``````for ( int i = 0; i <= NUM; i ++ ) // this loop executes NUM+1 times { // ... HotDogs_Sales[i] ; // the last time around, i==NUM // ... }``````
 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123`` `````` #include #include #include using namespace std ; float calc_HotDogs_Total (float[],int, float & , int &); float calc_IceCream_Total (float[], int , int &); float calc_Grand_Total (float , float ); void displayResults (int[], float[], float[] , float, float , float, int, int, float, int); int main () { const int NUM = 7; float HotDogs_Sales[NUM], IceCream_Sales[NUM], HotDogs_Total_Sales = 0, IceCream_Total_Sales = 0, Grand_Total = 0, Most_Sold = 0; int Days[NUM] , Max_IceCream_Sales = 0, Day2 ; cout << " ************* NUMBER OF HOT DOGS ************* \n" << endl; for ( int i = 0 ; i < NUM; i ++ ) { Days[i] = i+1 ; } for (int i = 0 ; i < NUM ; i ++) { cout << " Please enter number of hot dogs sold: " ; cin >> HotDogs_Sales[i] ; } cout << "\n************* NUMBER OF Ice Cream ************* \n " << endl; for ( int i = 0 ; i < NUM ; i++) { cout << " Please enter number of ice cream sold: " ; cin >> IceCream_Sales[i]; } HotDogs_Total_Sales = calc_HotDogs_Total ( HotDogs_Sales, NUM , Most_Sold , Day2 ); IceCream_Total_Sales = calc_IceCream_Total ( IceCream_Sales, NUM , Max_IceCream_Sales); Grand_Total = calc_Grand_Total ( IceCream_Total_Sales, HotDogs_Total_Sales ); displayResults (Days, IceCream_Sales, HotDogs_Sales, IceCream_Total_Sales, HotDogs_Total_Sales , Grand_Total, NUM, Max_IceCream_Sales, Most_Sold, Day2 ) ; return 0 ; } float calc_HotDogs_Total ( float HotDogs_Sales[] ,int NUM, float &Most_Sold , int& Day2 ) { float HotDogs_Total_Sales = 0 ; HotDogs_Sales ; for (int i = 0 ; i < NUM ; i++ ) { HotDogs_Total_Sales = HotDogs_Sales[i] + HotDogs_Total_Sales ; } for (int i = 0 ; i < NUM ; i++ ) { if (HotDogs_Sales[i] > Most_Sold ) { Most_Sold = HotDogs_Sales[i]; Day2 = i + 1 ; } } return HotDogs_Total_Sales ; } float calc_IceCream_Total ( float IceCream_Sales[], int NUM , int &Max_IceCream_Sales) { float IceCream_Total_Sales = 0 ; IceCream_Sales; Max_IceCream_Sales = 0 ; for ( int i = 0 ; i < NUM ; i++ ) { IceCream_Total_Sales = IceCream_Sales[i] + IceCream_Total_Sales ; if (IceCream_Sales[i] >= 250) { Max_IceCream_Sales = Max_IceCream_Sales + 1; } } return IceCream_Total_Sales ; } float calc_Grand_Total ( float IceCream_Total_Sales, float HotDogs_Total_Sales ) { float Grand_Total = IceCream_Total_Sales + HotDogs_Total_Sales ; return Grand_Total ; } void displayResults (int Days[], float HotDogs_Sales[], float IceCream_Sales[], float IceCream_Total_Sales, float HotDogs_Total_Sales , float Grand_Total, int NUM, int Max, float Most_Sold , int Day_Sold ) { cout << setiosflags(ios::fixed) << setiosflags(ios::showpoint) << setprecision(2); cout << "\n\n\t\tLittle League Ball Park " << endl ; cout << " \t\t Sales Report\t\t" << endl ; cout << "\t\tWeek of June 12, 2011\t\t\n\n" << endl; cout << setw(15) << " Day "<< setw(15) << " Ice Cream " << setw(15) << " Hot Dogs " << endl ; cout << setw(15) << " --- "<< setw(15) << " --------- " << setw(15) << " -------- " << endl ; for ( int i = 0 ; i < NUM ; i++ ) { cout << setw(15) << Days [i] << setw(14) << HotDogs_Sales[i] << setw(14) << IceCream_Sales[i] << endl ; } cout << "\n\n\tGrand Total = \$" << Grand_Total << endl; cout << "\n\tWeekly total of ice cream sales is = \$"<< IceCream_Total_Sales << endl; cout << "\n\tWeekly total of hot dogs sales is = \$" << HotDogs_Total_Sales << endl ; cout << "\n\tDay Number # "<< Day_Sold << " sold the most Hot Dogs = \$ " << Most_Sold << endl ; cout << "\n\tIce Cream sales was over \$250 " << Max << " time this week\n\n " << endl ; return; }``````
can anyone help me to re-write this program without using " int & " .
because my prof. didn't liked it.
"its dangerous"
&& i also need \$ sign !!
Last edited on
 can anyone help me to re-write this program without using " int & " .

Replace all the `int&` with `int`
Last edited on
I already tried it its giving me run-time error.
An error at run time has nothing to do with changing all the `int&` to `int`. An error at run time will most likely be you reading/writing to memory that you shouldn't.
Last edited on
It may be, if your are passing the parameter by reference in order to get the array size.

@jenny22: I could not reproduce the crash.
Get a debugger, perform a backtrace.
Umm im running without debugging ..and my teacher dont want me to use int& so now im stuck..
 Umm im running without debugging

Well that's easily fixed. Run it with debugging.

I can run the code above without crash (having swapped all the int& for int). What inputs are you giving it that cause a crash?
Topic archived. No new replies allowed.

You are using a version without Ads of this website. Please, consider donating: