struct 객체에 몇 개의 값을 저장하려고하는데 사용자가 "yes"를 입력 할 때까지 프롬프트를 반복하고 싶습니다. 나는 그것을 위해 do-while 루프를 사용하고 싶다. 나는 이미 첫 번째 "성"의 읽기로 실패하고있다. 입력 할 때 프로그램이 멈 춥니 다 (오류 없음). do-while을 사용하지도 않습니다. 왜냐하면 while() 상태에서 작동하는지 확실하지 않기 때문입니다. 당신의 형식 지정자로
C 및 do-while 루프를 사용하여 struct 객체에 값 저장
#include <ctype.h>
#include <stdio.h>
#include <string.h>
struct employeelist
{
char last[6];
char first[6];
int pnumber;
int salary;
};
int main()
{
struct employeelist employee[5];
char check;
//do
//{
printf("Hello. Please type in the last name, the first name, the personal number and the salary of your employees.\n");
printf("Last name: ");
scanf("%c", employee[1].last);
printf("First name: ");
scanf("%c", employee[1].first);
printf("Personal number: ");
scanf("%d", &employee[1].pnumber);
printf("Salary: ");
scanf("%d", &employee[1].salary);
printf("You have more employess (yes/no)?: ");
scanf("%c", &check);
//}while (scanf("yes"));
return 0;
}
실제로 질문하지 않았 음을 알고 있습니까? 당신은 많은 코드를 버리고 "작동하지 않는다"고 말했다. – abelenky
죄송합니다, 다음 번에 더 구체적으로하려고 노력할 것입니다. 그리고 이것은 내가 학교에서 겪고있는 숙제가 아닙니다. 나는 혼자 공부하고 있습니다. – Ordo