Input data into struct

why i can't enter data into struct?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
 #include <iostream>
#include <new>
#include <cstdlib>
#include <iomanip>

using namespace std;

struct DataStudent{
	char name[20];
	char MSV[3];
	char name_class[5];
	float aver_grade;
};
int main()
{
	DataStudent *ds;
	int n,i;
	
	cout<<"Amount of student to be entered: ";
	cin>>n;
	
	ds = new DataStudent[n+1];
	if (ds == NULL){
		cout<<"Error!!!"<<endl;
		exit(1);
	}
        //iput data
	for (i = 0; i < n; i++) {
		cout<<"Student #"<<i<<": "<<endl;
		cout<<"Name: ";
		cin.get(ds[i].name,20);
		cout<<endl<<"MSV: ";
		cin.get(ds[i].MSV,3);
		cout<<endl<<"Class: ";
		cin.get(ds[i].name_class,5);
		cout<<endl<<"Average Grade: "<<endl;
		cin>>ds[i].aver_grade;
	}
	for (i = 0; i < n-1; i++)
		for(int j = i+1; j< n; j++)
			if(ds[i].aver_grade < ds[j].aver_grade){
				DataStudent temp = ds[i];
				ds[i] = ds[j];
				ds[j] = temp;
			}
	cout<<setiosflags(ios::showpoint)<<setprecision(1);
        //display data
	for (i = 0;i < n; i++)
		cout<<ds[i].MSV<<setw(3)<<ds[i].name<<setw(5)<<ds[i].name_class<<endl
                    <<"Average Grade: "<<ds[i].aver_grade;
	delete ds;
	return 0;
}
Last edited on
Be more precise what is happening. Does it skips over name input by the way?
Yes, it skips over name input
Topic archived. No new replies allowed.