issue with functions


I am doing a project for school in which part of it is printing out array values. I call to my print_values function to cout the values and when i run it, it had no errors but will not run. If i get rid of everything but the first 2 lines it works. but as soon as i make another line, no matter what it is, it will not run. It is like it doesnt have enough room within the function to handle more than a couple lines. please help
 

void print_values()
{
cout << "Value 1 = " << value[0] << endl;
cout << "Value 2 = " << value[1] << endl;
cout << "Value 3 = " << value[2] << endl;
cout << "Value 4 = " << value[3] << endl;
cout << "Value 5 = " << value[4] << endl;
cout << "Value 6 = " << value[5] << endl;
cout << "Value 7 = " << value[6] << endl;
cout << "Value 8 = " << value[7] << endl;
cout << "Value 9 = " << value[8] << endl;
cout << "Value 10 = " << value[9] << endl;

cout << "Press 0 to return to the main menu" << endl;
cin >> entry;

if (entry==0)
{
display_menu();
}
}
closed account (48T7M4Gy)
Could be an out of range problem with the array being passed incorrectly. Would need to see all your code.
Last edited on
#include <iostream>
#include <stdlib.h>
using namespace std;

float entry = 0;
float value[10]={10,20,30,40,50,60,70,80,90,100};
void display_menu ();

void add_values();
void edit_values();
void print_values();
void display_stats();
void exit_program();

int main()
/*cout welcome and have the user choose an option
then have main jump to my menu displaying the options*/

{
cout<< "Welcome!" <<endl << "Please select an option" <<endl;
display_menu ();
}
/*Have display menu display the options.
Have if statements to deal with each option.
Depending on which option the user selects,
have the if statement call the selected function */

void display_menu ()
{
cout<< "1) Add a value" <<endl;
cout<< "2) Edit values" <<endl;
cout<< "3) Print values" <<endl;
cout<< "4) Display statistics" <<endl;
cout<< "5) Exit the program" <<endl;



while(entry != -15)
{
cin>>entry;

if (entry == 1)
void add_values();

if (entry == 2)
void edit_values();

if (entry == 3)
print_values();

if (entry == 4)
void display_stats();

if (entry == 5)
{
exit_program();
return;
}
}

}
// Create each individual function for the menu to call to

/*In the function add values, prompt the user to enter 10 numbers and have them cin there entry. create a loop in which
the user can input the numbers which will be stored in an array. creat an if statement that will cout an error statement
if the value of the entry is not within the range. If the user inputs an 11th number, cout an error statement informing the
user that they have entered the max amount of numbers.*/

void add_values(void)
{
/*
0
0
0
0
*/


}

/*Allow the user to view the entered values and overwrite those values with a new entry */
void edit_values(void)
{
/*
0
0
0
0
*/
}

/*Have the function display the values the user entered*/

void print_values()
{
cout << "Value 1 = " << value[0] << endl;
cout << "Value 2 = " << value[1] << endl;
cout << "Value 3 = " << value[2] << endl;
cout << "Value 4 = " << value[3] << endl;
cout << "Value 5 = " << value[4] << endl;
cout << "Value 6 = " << value[5] << endl;
cout << "Value 7 = " << value[6] << endl;
cout << "Value 8 = " << value[7] << endl;
cout << "Value 9 = " << value[8] << endl;
cout << "Value 10 = " << value[9] << endl;

cout << "Press 0 to return to the main menu" << endl;
cin >> entry;

if (entry==0)
{
display_menu();
}
}

/*display the number of entries, the largest number, lowest number, and average*/
void display_stats(void)
{
/*
0
0
0
0
*/
}

/*give the user an option to exit the program or to return to the menu.
If the user wants to exit, cout goodbye and end the program.*/
void exit_program()
{
cout<< "Are you sure you want to exit?" << endl << "1-Yes" << endl << "2-No" <<endl;
cin>> entry;
if(entry==1)
{
cout <<"Goodbye";
return;
}
else if(entry==2)
{
display_menu();
}
}

Topic archived. No new replies allowed.