Hey. I am writing a code which uses 4 separate functions, and are able to be called from the main function, and within them, an array is used to store 10 numbers, edit them if i want to change a value, print what values I had entered, and enter the range/median of them. I am able to store 10 numbers, but only able to edit one of them as i please in the 'edit_value' function. Is there a way to be able to change more than one value of an array without messing up my function? Any value over 4, automatically terminated my program. I dont get it! and how am i able to display the highest/lowest and the average? Thank you!
#include <iostream>
#include <cstdlib>
usingnamespace std;
void display_menu(), add_values(), edit_value(), display_stats(), print_values(), exit_program();
int number; float stored_values[10]; int i; int element_to_change; int editted;
int main()
{
cout<<"For this program to work, follow instructions."<<endl<<endl;
display_menu();
cout<<"Thanks for using my program! Please like and subscribe for more."<<endl;
cout<<"Enjoy the real world once again, and have a great day!"<<endl;
return 0;
}
void display_menu()
{
while(number<5)
{
cout<<"What would you like to do? Please pick a number within () for a selection."<<endl;
cout<<"(1) Add a Value"<<"\n(2) Edit a Value"<<"\n(3) Print a value"<<"\n(4) Display statistics"<<"\n(5) Quit the program"<<endl;
cin>>number;
if (number==1)
add_values();
if (number==2)
edit_value();
if (number==3)
print_values();
if (number==4)
display_stats();
if (number==5)
{exit_program(); cout<<"\a\a";}
}
}
////////////ADD/////////////////////////ADD/////////////////////ADD////////////////////////ADD//////////////////////ADD///////////////////////ADD////////////
void add_values()
{
cout<<"This is the add section!"<<endl<<endl;
cout<<"Please enter up to 10 numbers, and let the compiler do its magic."<<endl;
for(int i = 0; i < 10; ++i)
{
cin>> stored_values[i];
cout<< "Stored value of ["<< i << "]"<<" is: "<<stored_values[i]<<endl;
}
cout<<"Section complete!"<<endl<<endl;
}
///////////EDIT///////////////////////EDIT////////////////////EDIT///////////////////////EDIT/////////////////////EDIT///////////////////////EDIT////////////
void edit_value()
{
cout<<"This is the edit section!"<<endl<<endl;
cout<<"Enter a new value to be stored"<<endl;
cin>>number;
if (element_to_change=7)
stored_values[6]=number;
}
////////////PRINT///////////////////////PRINT////////////////////PRINT////////////////////////PRINT///////////////////PRINT////////////////////PRINT////////
void print_values()
{
cout<<"This is the print section!"<<endl<<endl;
cout<<"Displaying Values: "<<endl;
for (int i=0; i<10; ++i)
{
cout<<"Stored Values in the array of ["<<i<<"]= "<<stored_values[i]<<endl;
}
cout<<endl;
}
////////////STATS///////////////////////STATS/////////////////STATS////////////////////STATS//////////////////STATS/////////////////////STATS///////////////
void display_stats()
{
cout<<"This is the stats section!"<<endl<<endl;
}
///////////EXIT////////////////////////EXIT//////////////////EXIT/////////////////////EXIT////////////////////EXIT//////////////////////EXIT////////////////
void exit_program()
{
cout<<"This is the exit section!"<<"\n I hope you enjoyed using this program, please come again!"<<endl;
}