NEED HELP WITH FINAL PROJECT

Hey guys,
I have a final project due in three days and I cant get arrays, If someone can help you out, It will be highly appreciated. I have all the details and my code in here. The main problems are the ARRAYS with their CASE.
Thank you

/* Write a program that implements the following functions:
double add( double, double ) - function that returns the sum of 2 numbers.
double sub( double, double ) - function that returns the difference of 2 numbers.
double mul( double, double ) - function that returns the product of 2 numbers.
double div( double, double ) - function that returns the quotient of 2 numbers.
If the function attempts to divide by 0, it should return 0 instead.
double add( double[], int ) - function that accepts an array of doubles and the size of the array.
It returns the sum of all the elements of the array. This is an overloaded function.
double avg( double[], int ) - function that accepts an array of doubles and the size of the array.
It returns the avg of all the elements of the array.
void sort( double[], int ) - function that accepts an array of doubles and the size of the array.
The function sorts the array using the sorting algorithm of your choice.
int search( double[], int, double) - function that accepts an array of doubles, the size of the array, and a value to search for.
Returns the position within the area if target found, -1 otherwise.
void save( double[], int ) - function that accepts an array of doubles and the size of the array.
Writes all of the values inside the array to a text file on disk.
UPDATED!!!!
void print( double[], int ) - a function that accepts an array of doubles and the size of the array.
Displays all the values inside the array to the screen.

int main() should implement a menu from which the user may select an option:
(+) Add Two Values
(-) Sub Two Values
(*) Mul Two Values
(/) Div Two Values
(I) nput Values
(P)rint Values
(S)um Array
S(o)rt Array
S(e)arch Array
(A)vg of Array
(Q)uit
Based on the user's selection, the appropriate function will be called and output displayed.
The user should be able to select options repeatedly until the user decides to quit.
You are free to decide the length of the array. It can be static or dynamic.
A do-while loop and switch statement might be easiest, but you are free to implement your
solution as you wish using concepts covered during the course.
Input validation: The program should only accept valid menu selections.*/

#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;

// Functions
void selection();
double AVG(double arr[], int size);
int main()
{

int selection;
double X;
double Y;

// Constants for the menu.
const int ADD = 1;
const int SUB = 2;
const int MUL = 3;
const int DIV = 4;
const int INPUT = 5; // An input array.
const int PRINT = 6; // A print array.
const int SUM = 7; // A sum array.
const int SORT = 8; // A sort array.
const int SEARCH = 9; // A search array
const int AVG = 10; // An average array.
const int QUIT = 11;

// Constants for ADD, SUB, MUL, DIV
int X; // value for X
int Y; // value for Y

// Variable Formulas
double result;

// Numeric Output Formatting.
cout << fixed << showpoint << setprecision(2);

do
{
// Display the menu.
cout << "What would you like to do:\n"
<< "1. Add two numbers\n"
<< "2. Subtract two numbers\n"
<< "3. Multiply two numbers\n"
<< "4. Divide two numbers\n"
<< "5. Save the numbers to a file\n"
<< "6. Display the numbers on the screen\n"
<< "7. Search numbers for a value\n"
<< "8. Sort the set of numbers\n"
<< "9. Find sum of set of numbers\n"
<< "10.Find the average of set of numbers\n"
<< "11. Quit the program\n";
cin >> selection;

// Validate the Menu Selection.
while (selection < ADD || selection > QUIT)
{
cout << "Please enter a valid menu choice: \n";
cin >> selection;
}

// Process the menu choice.
if ( selection != QUIT)
{
// Get the value for X and Y.
cout << " Please enter a value for X: \n";
cin >> X;

cout << " Please enter a value for Y: \n";
cin >> Y;

// Respond to the menu choice.
switch (selection)
{
case ADD:
result = X + Y;
break;
case SUB:
result = X - Y;
break;
case MUL:
result = X * Y;
break;
case DIV:
result = X / Y;
if (Y = 0) result = 0;
break;
case INPUT:

case PRINT:

case SUM:

case SORT:

case SEARCH:

case AVG:

}
// Display the answer
cout << "The result is :" << result << endl;
}
} while (selection != QUIT);
cin.get();
return 0;
}
Hi @WALIA794,

This is my
approach i
hope this may
help you.

(I can't post the whole output)


Eyenrique-MacBook-Pro:~ Eyenrique$ ./FinalProject 
(+) Add Two Values
(-) Sub Two Values
(*) Mul Two Values
(/) Div Two Values
(I) nput Values
(P)rint Values
(S)um Array
S(o)rt Array
S(e)arch Array
(A)vg of Array
(Q)uit
Select: +
Enter number: 33
Enter number: 20

Result: 33.00+20.00=53.00

(+) Add Two Values
(-) Sub Two Values
(*) Mul Two Values
(/) Div Two Values
(I) nput Values
(P)rint Values
(S)um Array
S(o)rt Array
S(e)arch Array
(A)vg of Array
(Q)uit
Select: i
Enter 5 values:
Enter number: 300
Enter number: 20
Enter number: 77
Enter number: 55
Enter number: 19

Input was entered

(+) Add Two Values
(-) Sub Two Values
(*) Mul Two Values
(/) Div Two Values
(I) nput Values
(P)rint Values
(S)um Array
S(o)rt Array
S(e)arch Array
(A)vg of Array
(Q)uit
Select: o

Sorted array

(+) Add Two Values
(-) Sub Two Values
(*) Mul Two Values
(/) Div Two Values
(I) nput Values
(P)rint Values
(S)um Array
S(o)rt Array
S(e)arch Array
(A)vg of Array
(Q)uit
Select: p


19.00 20.00 55.00 77.00 300.00


(+) Add Two Values
(-) Sub Two Values
(*) Mul Two Values
(/) Div Two Values
(I) nput Values
(P)rint Values
(S)um Array
S(o)rt Array
S(e)arch Array
(A)vg of Array
(Q)uit
Select: Q


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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
//FinalProject.cpp
//Write your description program here.

#include <iostream>
using std::cout;
using std::cin;
using std::endl;
using std::fixed;
using std::showpoint;

#include <iomanip>
using std::setprecision;

#include <string>
using std::string;

#include <fstream>
using std::ofstream;

double add(double number1,double number2); //function prototypes
double sub(double number1,double number2);
double mul(double number1,double number2);
double div(double number1,double number2);

double add(double array[],int const SIZE);
double avg(double array[],int const SIZE);
void sort(double array[],int const SIZE);
int search(double array[],int const SIZE,double const KEY);
void save(double array[],int const SIZE);

void print(double array[],int const SIZE);

//Extra functions
double inputValue();
void inputArrayValues(double array[],int const SIZE);
int Menu();
void clearInput();

int main(){

bool theUserWantToContinue=true;
int choice;
int const SIZE=5;
double numbers[SIZE]={0};

cout<<fixed<<showpoint<<setprecision(2);

while(theUserWantToContinue){
	choice=Menu();
	double number1,number2;
	switch(choice){
		case 1:
			number1=inputValue();
			number2=inputValue();
			cout<<"\nResult: "<<number1<<'+'<<number2<<'='<<add(number1,number2)
			<<'\n'<<endl;
			clearInput();
			
		break;
		case 2:
			number1=inputValue();
                        number2=inputValue();
                        cout<<"\nResult: "<<number1<<'-'<<number2<<'='<<sub(number1,number2)
			<<'\n'<<endl;
			clearInput();
		break;
		case 3:
			number1=inputValue();
                        number2=inputValue();
                        cout<<"\nResult: "<<number1<<'*'<<number2<<'='<<mul(number1,number2)
			<<'\n'<<endl;
			clearInput();
		break;
		case 4:
			number1=inputValue();
                        number2=inputValue();
			if(number2==0){
				cout<<"\nError: DIVIDE BY ZERO\n"<<endl;
			}else{
                        cout<<"\nResult: "<<number1<<'/'<<number2<<'='<<div(number1,number2)
			<<'\n'<<endl;
			}//end if..else
			clearInput();
		break;
		case 5:
			cout<<"Enter "<<SIZE<<" values:\n";
			inputArrayValues(numbers,SIZE);
			cout<<"\nInput was entered\n"<<endl;
			save(numbers,SIZE);
			clearInput();
		break;
		case 6:
			print(numbers,SIZE);

		break;
		case 7:
			cout<<"\nThe sum of array is: "<<add(numbers,SIZE)<<'\n'<<endl;
		break;
		case 8:
			sort(numbers,SIZE);
			cout<<"\nSorted array\n"<<endl;
			save(numbers,SIZE);
		break;
		case 9:
			cout<<"Search number\n";
			number1=inputValue();
			int position;
			position=search(numbers,SIZE,number1);
			if(position!=-1){
				cout<<'\n'<<number1<<" is in subscript array:  "
				<<position<<'\n'<<endl;
			}else{
				cout<<'\n'<<number1<<" NOT FOUND\n"<<endl;
			}//end if..else
			clearInput();
		break;
		case 10:
			double average;
			average=avg(numbers,SIZE);
			cout<<"\nAverage: "<<average<<'\n'<<endl;
		break;
		case 11:
			theUserWantToContinue=false;
		break;	
	}//end switch
	
}//end while



return 0; //indicates success
}//end main

int Menu(){
	int choice=0;
	bool wrongInputIsEntered=true;
	string str;
	
		
		cout<<"(+) Add Two Values\n"
		<<"(-) Sub Two Values\n"
		<<"(*) Mul Two Values\n"
		<<"(/) Div Two Values\n"
		<<"(I) nput Values\n"
		<<"(P)rint Values\n"
		<<"(S)um Array\n"
		<<"S(o)rt Array\n"
		<<"S(e)arch Array\n"
		<<"(A)vg of Array\n"
		<<"(Q)uit\n"
		<<"Select: ";
        	getline(cin,str);

        	while(wrongInputIsEntered){
                if(str.size()>1){
                        cout<<"Enter a valid option\nEnter option again: ";
                        getline(cin,str);
                }else if(!(str=="/"||str=="+"||str=="-"||str=="*"||str=="I"
			||str=="i"||str=="P"||str=="p"||str=="S"||str=="s"
			||str=="O"||str=="o"||str=="E"||str=="e"
                        ||str=="A"||str=="a"||str=="Q"||str=="q")){
                
                        cout<<"$Enter a valid option\nEnter option again: ";
                        getline(cin,str);
                }else{
                        wrongInputIsEntered=false;
                }//end if..else..else
        	}//end while

		if(str=="+"){
			choice=1;
		}else if(str=="-"){
			choice=2;
		}else if(str=="*"){
			choice=3;
		}else if(str=="/"){
			choice=4;
		}else if(str=="I"||str=="i"){
			choice=5;
		}else if(str=="P"||str=="p"){
			choice=6;
		}else if(str=="S"||str=="s"){
			choice=7;
		}else if(str=="O"||str=="o"){
			choice=8;
		}else if(str=="E"||str=="e"){
			choice=9;
		}else if(str=="A"||str=="a"){
			choice=10;
		}else if(str=="Q"||str=="q"){
			choice=11;
		}//end if..else..else..


return choice;			
}//end function Menu

void inputArrayValues(double array[],int const SIZE){
	double value;
	for(int i=0;i<SIZE;i++){
		value=inputValue();
		array[i]=value;
	}//end for
}//end function inputArrayValues

double inputValue(){
	double value;
	cout<<"Enter number: ";
	cin>>value;
	while(cin.fail()){
		cin.clear();
		cin.ignore(1000,'\n');
		cout<<"NUMBERS ONLY\nEnter number again: ";
		cin>>value;
	}//end while

return value;
}//end function inputValue

void save(double array[],int const SIZE){
	ofstream myfile;
	 myfile.open("Dex.txt");
	for(int i=0;i<SIZE;i++){
		myfile<<array[i]<<((i+1)%5==0?'\n':' ');
	}//end for
	myfile.close();		
}//end function save

int search(double array[],int const SIZE,double const KEY){
	for(int i=0;i<SIZE;i++)
		if(array[i]==KEY) return i;

return -1;
}//end function search

void print(double array[],int const SIZE){
	cout<<'\n'<<endl;
	for(int i=0;i<SIZE;i++)
		cout<<array[i]<<((i+1)%5==0?'\n':' ');

cout<<'\n'<<endl;
}//end function print

double add(double number1,double number2){
	return number1+number2;
}//end add function

double sub(double number1,double number2){
	return number1-number2;
}//end function sub

double mul(double number1,double number2){
	return number1*number2;
}//end function mul

double div(double number1,double number2){
	double result;
	if(number2!=0){
		result=number1/number2;
		return result;
	}//end if

return 0;
}//end function div

double add(double array[],int const SIZE){
	double sum=0;
		for(int i=0;i<SIZE;i++)
			sum+=array[i];


return sum;
}//end function add

double avg(double array[],int const SIZE){
	double average;
	double sum;
		sum=add(array,SIZE);
	average=sum/SIZE;

return average;	
}//end function avg

void sort(double array[],int const SIZE){
	bool swap=true;
int number_swap=0;
while(swap){
	for(int i=0;i<SIZE-1;i++){
		if(array[i+1]<array[i]){
			int tmp;
			tmp=array[i+1];
			array[i+1]=array[i];
			array[i]=tmp;
			number_swap++;	
		}//end if
	}//end for
	
	if(number_swap==0)
		swap=false;
	else{
		number_swap=0;
		
	}//end if..else
}//end while
}//end function sort


void clearInput(){
	cin.clear();
	cin.ignore(1000,'\n');
}//end function clearInput 
Topic archived. No new replies allowed.