실행하면 org에 있는게 전체평균보다 크면 gr1으로 가고 아니면 gr2로 가게 만들어서 출력하려고 하는데 출력이 제대로 안되...
어떡하지
#include <iostream>
#include <string>
using namespace std;
struct score{
char name[20];
int mid;
int final;
float avg;
};
struct group1{
char name[20];
int mid;
int final;
float avg;
};
struct group2{
char name[20];
int mid;
int final;
float avg;
};
int main(void)
{
int i,size;
cout<<"입력받을 사람 수를 입력하시오. :";
cin>>size;
struct score *org = new struct score[];
struct group1 *gr1 = new struct group1[];
struct group2 *gr2 = new struct group2[];
for(i = 0; i < size; i++)
{
cout<<i+1<<"번째 이름을 입력하시오. :";
cin>>org[i].name;
cout<<i+1<<"번째 사람의 중간고사 점수를 입력하시오. :";
cin>>org[i].mid;
cout<<i+1<<"번째 사람의 기말고사 점수를 입력하시오. :";
cin>>org[i].final;
org[i].avg = ((float)org[i].mid+(float)org[i].final)/2;
}
cout<<endl;
cout<<"Original Student Info"<<endl;
for(i = 0; i < size; i++)
{
cout<<i+1<<". "<<org[i].name<<", "<<org[i].mid<<", "<<org[i].final<<", "<<org[i].avg<<endl;
}
cout<<endl;
float tavg=0.0;
for(i = 0; i < size; i++)
{
tavg += org[i].avg;
}
tavg = tavg/(float)size;
cout<<tavg<<endl;
//or을 gr1, gr2에 나누기
int j,k;
for(i = 0,j = 0,k = 0; i < size; i++)
{
if(org[i].avg >= tavg)
{
strcpy_s(gr1[j].name, org[i].name);
gr1[j].mid = org[i].mid;
gr1[j].final = org[i].final;
gr1[j].avg = org[i].avg;
j++;
continue;
}
else
{
strcpy_s(gr2[k].name, org[i].name);
gr2[k].mid = org[i].mid;
gr2[k].final = org[i].final;
gr2[k].avg = org[i].avg;
k++;
}
}
cout<<"Group 1 (higher than Total Average)"<<endl;
for(i = 0; i < j; i++)
{
cout<<i+1<<". "<<gr1[i].name<<", "<<gr1[i].mid<<", "<<gr1[i].final<<", "<<gr1[i].avg<<endl;
}
cout<<"Group 2 (lower than Total Average)"<<endl;
for(i = 0; i < j; i++)
{
cout<<i+1<<". "<<gr2[i].name<<", "<<gr2[i].mid<<", "<<gr2[i].final<<", "<<gr2[i].avg<<endl;
}
cout<<endl;
delete []org;
delete []gr1;
delete []gr2;
return 0;
}
댓글 0