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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include <iostream>
#include <iomanip>
#include <string>
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.

1
2
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:
1
2
3
4
5
6
for ( int i  = 0; i <= NUM; i ++ ) // this loop executes NUM+1 times
{
     // ...
     HotDogs_Sales[i] ;  // the last time around, i==NUM 
     // ...
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123

#include <iostream> 
#include <iomanip>
#include <string> 
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.