A
A
ALex duisenov2020-03-19 15:51:13
C++ / C#
ALex duisenov, 2020-03-19 15:51:13

Structure student had a problem who can help?

#include <iostream>
#include <string>
#define n 5
using namespace std;
struct studik{
    string FIO;
    int ocenka[n];
    int proverka;
    float stepuha;
    void getdata();
    void setdata();
    
};
void studik::setdata(){
    cout<<"вводим данные ешкин кошкин"<<endl;
    cout<<"ФИО"<<endl;
    getline(cin,FIO);
    cin.ignore();
    cout<<"оценки по математике,алгоритмам,психологии,физике,истории"<<endl;
    for(int i=0;i<n;i++){
        cin>>ocenka[i];
        
    }
        cout<<"степендия есть -1 нищий-2"<<endl;
        cin>>proverka;
        
        if(proverka==1){
            cout<<"введите насколько богат студент"<<endl;
            cin>>stepuha;
            
        }
        
    
}
void studik::getdata(){
    cout<<"выводим данные ешкин кошкин"<<endl;
    cout<<"ФИО"<<FIO<<endl;
    
    cout<<"оценки по математике,алгоритмам,психологии,физике,истории :"<<endl;
    for(int i=0;i<n;i++){
        cout<<ocenka[i]<<" ";}
        cout<<endl;
        if(proverka==1){
            cout<<" сколько денег у буржуя"<<" "<<stepuha<<endl;
            
        }
     
    
}


int main()
{
     const int N = 2; 							
  studik Student[N]; 
    for (int i=0; i<N; i++) Student[i].setdata(); 	
  for (int i=0; i<N; i++) Student[i].getdata();
 
    

    return 0;

the problem is that after writing the name of the second student, the program simply starts outputting the data of two students, but there is just garbage

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
res2001, 2020-03-19
@alex_memex

Everything is more or less normal.
Remove cin.ignore();
Replace withgetline(cin,FIO);cin >> FIO;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question