구조체를 통한 성적관리중에 문제가 생겼습니다 도와주세요 ㅠㅠ
일본드립
질문 제목 : 구조체를 통한 성적관리프로그램을 만드는중인데요;;이것을 실행시켜서 처음에 입력받으면 그냥 종료가 되더라고요 제가 원했던것은 10명을 다 입력받는거였는데요 ㅠ..ㅠ 안되네요 도와주세요 ㅠㅠ (빨간색으로 칠한부분이 문제 있는거같은데 break문을 잘못는거같기도하고;; 모르겠습니다.
제가 원하는것은 입력을하고 나서 다시 또선택문으로 돌아가서다시 하나 또 입력하는 형식인데 잘 안되네요;;
질문 내용 :
#include stdio.h
#include stdlib.h
struct student{
char name[21]; // 20 = 한글 9*2 =18 + 널문자(1)
int kor,eng,math;
int sum;
float avg;
};
void init_std(struct student *std) // 초기화
{
int i;
for(i=0;i10;i++){
std[i].kor = -1;
std[i].eng = -1;
std[i].math = -1;
}
}
void input_detail(struct student *std,int i)
{
printf(이름 : );
scanf(%s, std[i].name);
printf(국어 : );
scanf(%s, &std[i].kor);
printf(영어 : );
scanf(%s, &std[i].eng);
printf(수학 : );
scanf(%s, &std[i].math);
std[i].sum = std[i].kor + std[i].eng + std[i].math;
std[i].avg = (float)std[i].sum / 3;
}
void output_std(struct student *std)
{
int i;
printf(|%20s|%4s|%4s|%4s|%4s|%6s|\n,
이름, 국어, 영어, 수학, 합계, 평균);
for(i=0;i10;i++)
{
if(std[i].kor != -1){
printf(|%20s|%4s|%4s|%4s|%4s|%6.2f|\n,
std[i].name,std[i].kor,std[i].eng,std[i].math,std[i].sum,std[i].avg);
}
}
}
void input_std(struct student *std)
{
int i;
for(i=0;i10;i++)
{
if (std[i].kor == -1 || std[i].eng == -1 || std[i].math == -1)
break;
}
if(i==10){
printf(더이상 입력 불가능 합니다.\n);
return;
}
input_detail(std,i);
}
int main()
{
struct student std[10];
int sel;
init_std(std); // 구조체 배열 초기화
printf(==== 학생 성적관리 프로그램 =====\n);
printf(1. 입력 \n);
printf(2. 출력 \n);
printf(3. 수정 및 삭제 \n);
printf(0. 종료\n);
printf( );
scanf(%d, &sel);
switch(sel){
case 1:
input_std(std);
break;
case 2:
output_std(std);
break;
case 3:
break;
case 0:
printf(프로그램을 종료합니다.\n);
exit(0);
}
}
번호 | 제 목 | 글쓴이 | 날짜 |
---|---|---|---|
2693956 | PlaySound재생이 안됩니다!(C에 음악넣기) | 지존 | 2025-05-06 |
2693928 | &와 *의 사용에 관한 명확한 이해 | 제나 | 2025-05-06 |
2693903 | 반복문 설명좀요 ㅠㅠ (2) | 란새 | 2025-05-06 |
2693869 | stdio.h 는 왜 쓰는건가요? (1) | 큰꽃들 | 2025-05-06 |
2693842 | 포인터 변수의 주소값끼리 더하는 것에 대해서 질문드립니다. (1) | 진솔 | 2025-05-05 |
2693811 | 소수 출력;;;; | 화이트캣 | 2025-05-05 |
2693788 | 이런 함수는 없나요? (3) | 앤드류 | 2025-05-05 |
2693758 | txt파일 불러와서 행렬로 저장 | 큰애 | 2025-05-05 |
2693727 | scanf 오류 문제!! (2) | 큰나래 | 2025-05-04 |
2693704 | 구조체 주소록 문제인데 도와주세요 (2) | 도1도캣 | 2025-05-04 |
2693676 | 열혈강의 c언어 질문입니다 | 하양이 | 2025-05-04 |
2693647 | 12.620000 을요 12.620 으로 어떻게 표현해요? (2) | 파도 | 2025-05-04 |
2693619 | 타이틀 코드.. | 단순드립 | 2025-05-03 |
2693591 | 컴파일 에러에서 질문드립니다 (3) | 게자리 | 2025-05-03 |
2693463 | 동적할당 이용시 fwrite사용을 어떻게 해야하나요..? (10) | 일본어못해요 | 2025-05-02 |
2693387 | 배열문제입니다 수정오류캡쳐했습니다 (6) | 연하얀 | 2025-05-01 |
2693356 | text 입출력 내림차순 질문입니다 ㅠ | 빛글 | 2025-05-01 |
2693328 | C언어를이용해서 .txt파일 외에 다른 확장자 파일 삭제가 가능한지.. (2) | 대나무 | 2025-05-01 |
2693299 | 파일입출력 바이너리파일 | 독특한 | 2025-04-30 |
2693273 | 오류 (1) | 귀1여운렩 | 2025-04-30 |