Program is executable but when on run time it skip the qualification value and jump to highest

35 Views Asked by At
#include<iostream>
using namespace std;
struct teacher 
{
    char name[20];
    int id;
    char grade[20];
    char qual[20];
    char heighest[20];  
};


int main()
{
    teacher t1,*ptr_t1;
    ptr_t1=&t1;
    cout<<"please Enter your Name \n";
    gets(ptr_t1->name);
    cout<<"please Enter your grade\n";
    gets(ptr_t1->grade);
    cout<<"please Enter your ID \n";
    cin>>ptr_t1->id;
    cout<<"please Enter your Qualification \n";
    gets(ptr_t1->qual);
    cout<<"please Enter your heighest \n";
    gets(ptr_t1->heighest); 
    system("pause");
    return 0;
}

this is my code gets(ptr_t1->qual) is not accepting any value and my program jumped to gets(ptr_t1->heighest) i am facing problem in it

1

There are 1 best solutions below

1
On

You shouldn't be mixing cin with gets. Instead, you can always use cin:

#include<iostream>
using namespace std;

struct teacher 
{
    char name[20];
    int id;
    char grade[20];
    char qual[20];
    char heighest[20];  
};


int main()
{
    teacher t1,*ptr_t1;
    ptr_t1=&t1;

    cout << "please Enter your Name \n";
    cin >> ptr_t1->name;
    cout << "please Enter your grade\n";
    cin >> ptr_t1->grade;
    cout << "please Enter your ID \n";
    cin >> ptr_t1->id;
    cout << "please Enter your Qualification \n";
    cin >> ptr_t1->qual;
    cout << "please Enter your heighest \n";
    cin >> ptr_t1->heighest; 

    system("pause");
    return 0;
}