Changing array values

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!
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
  #include <iostream>
#include <cstdlib>
using namespace 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;
}
Last edited on
void display_stats()
{
cout<<"This is the stats section!"<<endl<<endl;
max= stored_values[0];
min = stored_values[0];
for (int i=0; i<10; ++i)
{
sum+=stored_values[i];
if(max<stored_values[i])
{
max = stored_values[i];
}
if(min>stored_values[i])
{
min = stored_values[i];
}
}
cout<<sum<<" "<<max<<" "<<min<<" "<<sum/10<<endl;
}
Wow thank you very much for helping with code to make mine work nicely! i appreciate the time you took to help me out. Thanks again!
Topic archived. No new replies allowed.