Displaying most profitable day

Sorry for posting entire code but would be much easier to help.

I am trying write a void function which will tally up the totals for each day and then display the most profitable day of the week.

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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
  #include "stdafx.h"
#include <iostream>
using namespace std;
#include <iomanip>
#include <string>
#include <fstream>  


struct Menu_Items
		{
			string Item;
			double Price;
		};

struct Orders
		{
			string Menu_Item_Ordered;
			string Day_of_Week;
			string CustomerID;
			int Quantity;
			double Line_Item_Total;

		};

const int NUM_MENU_ITEMS = 20;
const int ORDERS = 100;
const double PA_SALES_TAX = 1.06;

double GetPrice( Menu_Items [] , string );
void Biggest_Profit(Double[]);

int main()
{

	Menu_Items Menu_List[NUM_MENU_ITEMS];
	int i = 0;

	ifstream InFileMenu;
	InFileMenu.open("Menu.txt");
	ifstream InFileOrders;
	InFileOrders.open("Orders.txt");

	

	

	if ( InFileMenu.fail() )
	{
		cout << "The 'Menu.txt' file you have entered cannot be found!!!" << endl;
		system("pause");
	}
	else
	{
		cout << "The 'Menu.txt' file you have enetered was found!!" << endl;
		system("pause");


		string Item;
		double Price;

		while (InFileMenu >> Item >> Price)
		{
			cout << "The Menu item: #" << i + 1 << " is the " << Item << " and it cost: $" << Price << endl;
			Menu_List[i].Item = Item;
			Menu_List[i].Price = Price;
			i++;
		}


	}


	Orders Orders_Placed[ORDERS];
	int Orders_Index = 0;
	

	if (InFileOrders.fail())
	{
		cout << "The 'Orders.txt' file you have entered cannot be found!!!" << endl;
		system("pause");
	}
	else
	{
		cout << "The 'Orders.txt' file you have enetered was found!!" << endl << endl;
		system("pause");

		

		string Menu_Item_Ordered, Day_of_Week, Customer_ID;
		int Quantity, Max = 0, Num_of_Orders;
		double Line_Item_Total, Days_Profit;
		
		
		while ( InFileOrders >> Menu_Item_Ordered >> Quantity >> Day_of_Week >> Customer_ID )
		{
			
			cout << "Customer: " << Customer_ID << " ordered " << Quantity << " " << Menu_Item_Ordered << " on " << Day_of_Week << "." << endl << endl;

			Orders_Placed[Orders_Index].Menu_Item_Ordered = Menu_Item_Ordered;
			Orders_Placed[Orders_Index].Quantity = Quantity;
			Orders_Placed[Orders_Index].Day_of_Week = Day_of_Week;
			Orders_Placed[Orders_Index].CustomerID = Customer_ID;
			Orders_Index++;

			if (Orders_Index > Max)
			{
				Max = Orders_Index;
				Num_of_Orders = Orders_Index;
			}
			
		}
		cout << "There was a total of " << Num_of_Orders << " orders!!!" << endl;
		system("pause");

		
			
		 for (i = 0; i < Num_of_Orders; ++i)
		 {
			
			Line_Item_Total = Orders_Placed[i].Quantity * GetPrice(Menu_List, Orders_Placed[i].Menu_Item_Ordered) * PA_SALES_TAX;
			Orders_Placed[i].Line_Item_Total = Line_Item_Total;
			cout << "The line item total for " << Orders_Placed[i].Quantity << " " << Orders_Placed[i].Menu_Item_Ordered << " is: $" << setw(2) << fixed  << setprecision(2) << Orders_Placed[i].Line_Item_Total << endl;
		}
	}system("pause");

	
	
	 Biggest_Profit(Orders_Placed);
	 cout << Orders_Placed[i].Line_Item_Total << endl;
	 system("pause");

	
	







	return 0;
}

double GetPrice( Menu_Items Menu[], string  Item)
{
	int i = 0;
	for (i = 0; i < NUM_MENU_ITEMS; ++i)
	if (Menu[i].Item == Item)
		return Menu[i].Price;
	
}

void Biggest_Profit(double Orders_Total[])
{
	double MonTotals, TueTotals, WedTotals, ThuTotals, FriTotals, SatTotals, SunTotals;
	int i;
	double Winner;

	for (i = 0; i < ORDERS; ++i)
	{
		if (MonTotals < TueTotals)
			Winner = TueTotals;
		else if (WedTotals > Winner)
			Winner = WedTotals;
		else if (ThuTotals > Winner)
			Winner = ThuTotals;
		else if (FriTotals > Winner)
			Winner = FriTotals;
		else if (SatTotals > Winner)
			Winner = SatTotals;
		else if (SunTotals > Winner)
			Winner = SunTotals;
		else if (MonTotals > Winner)
			Winner = MonTotals;
	}


	return;
}



The void function must pass as a parameter a pointer to the first element of the Orders_Placed array. I have attempted to write this. But I do not think I am even close. I need to have 7 double variables that hold the totals for each day of the week. Those are the MonTotals , TueTotals , etc....

How do I get these totals for each day?

How do I fix this void function so that is displays the most profitable day. Also, would the function call be Biggest_Profit(Orders_Placed)??

The GetPrice function provides the price given a menu item.

P.S. Hints would be appreciated. Thanks!!
Last edited on
This can get you started!
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
...
Biggest_Profit(Orders_Placed, Menu_List);
...
void Biggest_Profit( Orders Orders_Total[], Menu_Items Something_Items_List[] )
{
double MonTotals = {0};  
	double TueTotals = {0}; 
	double WedTotals = {0}; 
	double ThuTotals = {0};  
	double FriTotals = {0}; 
	double SatTotals = {0}; 
	double SunTotals = {0}; 
	//int i;
	string Item;


	//I dont know what the Day_of_Week strings look like...
	for(int i = 0; i < ORDERS; i++ )
	{
		if( Orders_Total[ i ].Day_of_Week == "Tuesday")
		{
			Item = Orders_Total[ i ].Menu_Item_Ordered;
			TueTotals += ( GetPrice( Something_Items_List, Item )  *  Orders_Total[ i ].Quantity;
		}

		//mon, wed, thur, fri sat
		//...
	    
	}

double Winner = 0;
double Previous_Winner = 0;

	do{

	Previous_Winner = Winner;

	if( MonTotals > FriTotals )
	Winner = MonTotals;

	//Tue, Wed, Thur...
	
	}while( Winner != Previous_Winner;

	return;
}
Topic archived. No new replies allowed.