1. Not finding help here? Sign up for a free 30min tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

C++, char is not printing out

  1. Nov 11, 2011 #1
    1. The problem statement, all variables and given/known data
    After I typed in the name, and tested it by running " lookup " under "option". But the "name:" showed nothing.
    Code (Text):

    #include <iostream>
    #include <cstring>
    #include <cstdlib>
    using namespace std;
    const int name_length = 20;
    struct student
    {
    int idnum;
    char name[name_length];
    char gender;
    };

    void menu(int *);
    int main()
    {
        student kbccstudent[500];
        int p=5,y,procceed;
        for(int x=0; x<500; x++)
         {
                 kbccstudent[x].idnum = 0;
                 kbccstudent[x].name[0] = ' ';
                 kbccstudent[x].gender = ' ' ;
         }
        while(p!=4)
    {
        menu(&p);
        switch(p)
        {
        case(1):
                {
         cout<<"What entry to update? \n";
         cin>>y;
         cout<<"\nEnter student name? \n";
         cin.getline(kbccstudent[y].name, name_length);
         cin.ignore(name_length,'\n');
         cout<<"\nEnter student ID ? \n";
         cin>>kbccstudent[y].idnum;
         cout<<"\nEnter student gender? (m/f) \n";
         cin>>kbccstudent[y].gender;
         cout<<"Database updated. \n";
         break;
                }
         case(2):
                 {
         loop:
         cout<<"What entry to update? \n";
         cin>>y;
         cout<<"\nStudent record "<<y
              <<"\nName: "<<kbccstudent[y].name
              <<"\nID: "<<kbccstudent[y].idnum
              <<"\nGender: "<<kbccstudent[y].gender
              <<"\nPress 1 to procceed\n";
         cin>>procceed;  
         if(procceed == 1)
         {
         cout<<"\nEnter student name? \n";
         cin.getline(kbccstudent[y].name,name_length);
         cin.ignore(name_length,'\n');
         cout<<"\nEnter student ID ? \n";
         cin>>kbccstudent[y].idnum;
         cout<<"\nEnter student gender? (m/f) \n";
         cin>>kbccstudent[y].gender;
         cout<<"Database updated. \n";
         }
         else
         {
         cout<<"\nNot the right student. Going back\n";  
         goto loop;
         }
         break;
                }
         case(3):
                 {
         cout<<"What entry to lookup? \n";
         cin>>y;
         cout<<"\nStudent record "<<y
              <<"\nName: "<<kbccstudent[y].name
              <<"\nID: "<<kbccstudent[y].idnum
              <<"\nGender: "<<kbccstudent[y].gender;
         break;
                 }
         case(4):
                {
         cout<<"Warning , window to be closed.\n";
         system("pause");
         exit(0);
                 }
         }
    }
        system("pause");
        return 0;
    }
    void menu(int *p)
    {
         cout<<"\nStudent Record Database \n"
             <<"----------------------- \n"
             <<"Options \n"
             <<"1. Add student \n"
             <<"2. Update record \n"
             <<"3. Lookup record \n"
             <<"4. Quit \n"
             <<"Selection ? ";
         cin>>*p;
    }
     

    2. Relevant equations



    3. The attempt at a solution
     
  2. jcsd
  3. Nov 11, 2011 #2

    Mark44

    Staff: Mentor

    Have you entered any students yet? Before you can look up an individual student, you must first have added some students (menu choice 1).
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: C++, char is not printing out
Loading...