• Support PF! Buy your school textbooks, materials and every day products Here!

C++, char is not printing out

  • Comp Sci
  • Thread starter tebes
  • Start date
  • #1
39
0

Homework Statement


After I typed in the name, and tested it by running " lookup " under "option". But the "name:" showed nothing.
Code:
#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;
}

Homework Equations





The Attempt at a Solution

 

Answers and Replies

  • #2
33,286
4,990
Have you entered any students yet? Before you can look up an individual student, you must first have added some students (menu choice 1).
 

Related Threads on C++, char is not printing out

  • Last Post
Replies
1
Views
2K
  • Last Post
Replies
5
Views
1K
  • Last Post
Replies
4
Views
595
Replies
8
Views
3K
  • Last Post
Replies
4
Views
1K
Replies
6
Views
1K
Replies
3
Views
4K
Replies
26
Views
2K
Replies
3
Views
1K
Replies
4
Views
1K
Top