alright, this program i wrote pops a menu up letting me choose one of the four options, after i choose an option, and it does that function, how do i get the menu to pop back up again so the user can choose another option? instead, my program does the function, then quits. heres my code:

#include <iostream>

using std::cout;
using std::cin;
using std::endl;

 struct cardholder 
  {
    char name[10];        //name of student
    int SSN;              // social security number
    char cardtype[10];
    float balance;
  };

typedef struct cardholder CARD;

void addholder(CARD hold[], int arraycounter);
void printholder(CARD hold[]); 
//void findholders(CARD hold[]); 



int main()
{
   int menuvalue;	
   int arraycounter = 0;
   CARD holder[10];


       cout << "Select a option\n";
       cout << "   1 Enter a new holder\n";
       cout << "   2 Print holders information\n";
       cout << "   3 Find holder\n";
       cout << "   4 to quit\n";
       cin >> menuvalue;

if( menuvalue == 1 )
       addholder (holder, arraycounter);
else if ( menuvalue == 2 )
       printholder(holder);
//else if (menuvalue == 3)
  //       find_holders(holder);



   return 0;
}



void addholder(CARD hold[], int arraycounter)       // add holder function
{


    cout << "Enter student name\n";
    cin >> hold[arraycounter].name;

    cout << "Enter social security number\n";
    cin >> hold[arraycounter].SSN;

    cout << "Enter card type\n";
    cin >> hold[arraycounter].cardtype;

    cout << "Enter balance\n";
    cin >> hold[arraycounter].balance; 

arraycounter++;	
  
}


void printholder(CARD hold[])
{
  int social;
  social = 0;

  cout << "Please enter the social security number\n";
  cin >> social;

  for (int i = 0; i < 10; i++ )
  {
    if ( social == hold[i].SSN )
   {
cout << "Student SSN: " << hold[i].SSN << endl;
cout << "Student Name: "  << hold[i].name << endl;
cout << "Card Type: " << hold[i].cardtype << endl;
cout << "Balance: " << hold[i].balance << endl;
cout << endl;
    }
  }
}

USe do-while look like this:

do
{
cout << "Select a option\n";
cout << " 1 Enter a new holder\n";
cout << " 2 Print holders information\n";
cout << " 3 Find holder\n";
cout << " 4 to quit\n";
cin >> menuvalue;

if( menuvalue == 1 )
addholder (holder, arraycounter);
else if ( menuvalue == 2 )
printholder(holder);
//else if (menuvalue == 3)
// find_holders(holder);

}while (menuvalue!=4)

first of all answer me this, i noticed that in the show card info function you have it make a for loop and then if it is the right ssn it displays the info, i was wondering why you used a for loop here, it will cause the program to spit out the info to the user 10 times.

and you can also make it repeat by using another function like this.

#include <iostream>
#include <conio.h>

using std::cout;
using std::cin;
using std::endl;

 struct cardholder
  {
    char name[10];        //name of student
    int SSN;              // social security number
    char cardtype[10];
    float balance;
  };

typedef struct cardholder CARD;
void menu (CARD hold[], int arraycounter);
void addholder(CARD hold[], int arraycounter);
void printholder(CARD hold[]);
//void findholders(CARD hold[]);



int main()
{
   int arraycounter = 0;
   CARD holder[10];


menu (holder, arraycounter);



   return 0;
}



void addholder(CARD hold[], int arraycounter)       // add holder function
{


    cout << "Enter student name\n";
    cin >> hold[arraycounter].name;

    cout << "Enter social security number\n";
    cin >> hold[arraycounter].SSN;

    cout << "Enter card type\n";
    cin >> hold[arraycounter].cardtype;

    cout << "Enter balance\n";
    cin >> hold[arraycounter].balance;

arraycounter++;	

}


void printholder(CARD hold[])
{
  int social;
  social = 0;

  cout << "Please enter the social security number" << endl << endl;
  cin >> social;

  for (int i = 0; i < 10; i++ )
  {
    if ( social == hold[i].SSN )
   {
cout << "Student SSN: " << hold[i].SSN << endl;
cout << "Student Name: "  << hold[i].name << endl;
cout << "Card Type: " << hold[i].cardtype << endl;
cout << "Balance: " << hold[i].balance << endl;
cout << endl;
    }
  }
}
void menu (CARD hold[], int arraycounter)
{
   int menuvalue;
   CARD holder[10];


       cout << "Select a option\n";
       cout << "   1 Enter a new holder\n";
       cout << "   2 Print holders information\n";
       cout << "   3 Find holder\n";
       cout << "   4 to quit\n";
       cin >> menuvalue;

if( menuvalue == 1 ){
       addholder (holder, arraycounter);
       menu (holder, arraycounter);
}
else if ( menuvalue == 2 ){
       printholder(holder);
       menu (holder, arraycounter);
}
//else if (menuvalue == 3){
  //       find_holders(holder);
//}

else if (menuvalue == 4){
    int quit;
    cout << "Are you sure you wish to quit?" << endl << endl;
    cout << "1: Yes, quit." << endl;
    cout << "2: No, continue working." << endl;
    cin >> quit;
        if (quit == 1){
        void exit ();
        }
        else if (quit == 2){
        menu (holder, arraycounter);
        }
}
}

having a problem with this program errrrrr. alright, in the program i wrote below, after i enter 2 card holders, and try to print the first one, it just prints the last holder i entered, so my program should be keeping up to ten holders in memory, but if i enter one holder, then enter another, it just replaces the last one i entered with the first, its suppose to hold up to ten holders with their information, but mine just stores one at a time.....can anyone help?

#include <iostream>

using std::cout;
using std::cin;
using std::endl;

 struct cardholder 
  {
    char name[10];        //name of student
    int SSN;              // social security number
    char cardtype[10];
    float balance;
  };

typedef struct cardholder CARD;

void addholder(CARD hold[], int arraycounter);
void printholder(CARD hold[]); 
void findholders(CARD hold[]); 



int main()
{
   int menuvalue;	
   int arraycounter = 0;
   CARD holder[10];


do
{ 
cout << "Select a option\n";
cout << " 1 Enter a new holder\n";
cout << " 2 Print holders information\n";
cout << " 3 Find holder\n";
cout << " 4 to quit\n";
cin >> menuvalue;

if( menuvalue == 1 )
addholder (holder, arraycounter);
else if ( menuvalue == 2 )
printholder(holder);
else if (menuvalue == 3)
findholders(holder);

} while (menuvalue!=4);



   return 0;
}



void addholder(CARD hold[], int arraycounter)       // add holder function
{


    cout << "Enter student name\n";
    cin >> hold[arraycounter].name;

    cout << "Enter social security number\n";
    cin >> hold[arraycounter].SSN;

    cout << "Enter card type\n";
    cin >> hold[arraycounter].cardtype;

    cout << "Enter balance\n";
    cin >> hold[arraycounter].balance; 

arraycounter++;	
  
}


void printholder(CARD hold[])
{
  int social;
  social = 0;

  cout << "Please enter the social security number\n";
  cin >> social;

for (int i = 0; i < 10; i++ )
{
if ( social == hold[i].SSN )
{
cout << "Student SSN: " << hold[i].SSN << endl;
cout << "Student Name: "  << hold[i].name << endl;
cout << "Card Type: " << hold[i].cardtype << endl;
cout << "Balance: " << hold[i].balance << endl;
cout << endl;
}
}
}


void findholders(CARD hold[])
{
float flt = 0;

   cout << "Enter in a balance: " << endl;
   cin >> flt;

 for ( int i = 0; i < 10; i++ )
 {
   if ( flt <= hold[i].balance )
   {
cout << "Student SSN: " << hold[i].SSN << endl;
cout << "Student Name: "  << hold[i].name << endl; 
cout << "Card Type: " << hold[i].cardtype << endl;
cout << "Balance: " << hold[i].balance << endl;
cout << endl;
}
}      
}

Pass arraycounter as a reference or pointer or do this

if( menuvalue == 1 )
{
addholder (holder, arraycounter);
++arraycounter
};

and remove the other one in the function.


. You are creating a copy of it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.