Программа исполняемая, но во время выполнения она пропускает квалификационное значение и переходит на самое высокое - PullRequest
0 голосов
/ 03 мая 2020
#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;
}

это мой код получает (ptr_t1-> qual) не принимает никакого значения, и моя программа переходит к получает (ptr_t1-> heighest) я сталкиваюсь с проблемой в этом

1 Ответ

0 голосов
/ 03 мая 2020

Вы не должны смешивать cin с gets. Вместо этого вы всегда можете использовать 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;
}
...