수다닷컴

  • 해외여행
    • 괌
    • 태국
    • 유럽
    • 일본
    • 필리핀
    • 미국
    • 중국
    • 기타여행
    • 싱가폴
  • 건강
    • 다이어트
    • 당뇨
    • 헬스
    • 건강음식
    • 건강기타
  • 컴퓨터
    • 프로그램 개발일반
    • C언어
    • 비주얼베이직
  • 결혼생활
    • 출산/육아
    • 결혼준비
    • 엄마이야기방
  • 일상생활
    • 면접
    • 취업
    • 진로선택
  • 교육
    • 교육일반
    • 아이교육
    • 토익
    • 해외연수
    • 영어
  • 취미생활
    • 음악
    • 자전거
    • 수영
    • 바이크
    • 축구
  • 기타
    • 강아지
    • 제주도여행
    • 국내여행
    • 기타일상
    • 애플
    • 휴대폰관련
  • 프로그램 개발일반
  • C언어
  • 비주얼베이직

결국 if문 문제로 돌아왔군요 ㅜㅜ

하늘빛눈망울

2023.04.01

메인 함수의

if (service_time 0){service_time--;}if (service_time == 0){service_time=remove_customer(clock_temp);}if (service_time2 0){service_time2--;}if (service_time2 == 0){service_time2 = remove_customer2(clock_temp);}

이 부분이 문제가 있는것 같습니다

예를 든다면 고객1의 서비스 시간을 고객3이 덮어버림으로써

죄다 엉망이 되어버리는것 같습니다.
컴파일 해서 생기는 다른 오류는 아마 위에 있는 저걸 해결해볼려고 이리저리 발버둥치다가

꼬여버린 경우일꺼 같네요...ㅜㅜ소스코드

#include stdio.h#include conio.h#include stdlib.h#include math.h#include Windows.h#include time.henum {BLACK,/* 0 : BLACK */DARK_BLUE,/* 1 : DARK BLUE */DARK_GREEN,/* 2 : DARK GREEN */DARK_SKY_BLUE, /* 3 : DARK SKYBLUE */DARK_RED, /* 4 : DARK RED */DARK_VIOLET, /* 5 : DARK PURPLE */DARK_YELLOW, /* 6 : DARK YELLOW */GRAY, /* 7 : GRAY */DARK_GRAY, /* 8 : DARK GRAY */BLUE, /* 9 : BLUE */GREEN, /* 10 : GREEN */SKY_BLUE, /* 11 : SKYBLUE */RED, /* 12 : RED */VIOLET, /* 13 : PURPLE */YELLOW, /* 14 : YELLOW */WHITE, /* 15 : WHITE */};void Setcolor(int back_color, int fore_color) // 배경색, 글자색{int color = (back_color * 16) + fore_color;SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), color);}#define TRUE 1#define FALSE 0#define MAX_QUEUE_SIZE 100typedef struct{int id;int arrival_time;int service_time;int service_time2;}element;typedef struct{element queue[MAX_QUEUE_SIZE];int front, rear;}QueueType;QueueType queue;int duration = 10; // 시뮬레이션 시간double arrival_prob = 0.7; // 하나의 시간 단위에 도착하는 평균 고객의 수int max_serv_time = 5; // 하나의 고객에 대한 최대 서비스 시간int customers = 1; // 처음 고객 수int served_customers; // 서비스 받은 고객 수int waited_time; // 고객들이 기다린 시간int clock_temp;int que_count = 0;int que_count2 = 0;double random(){return rand() / (double)RAND_MAX;}int check_que(int num){if (num0){num-=1;}return num;}; // 1번 대기열int check_que2(int num){if (num0){num-=1;}return num;}; // 2번 대기열void error(char *message){fprintf(stderr, %s\n, message);exit(1);}void init(QueueType *q){q - front = q - rear = 0;}void init2(QueueType *q){q - front = q - rear = 0;}int is_empty(QueueType *q){return (q - front == q - rear);}int is_empty2(QueueType *q){return/return (q - front == q - rear);}int is_full(QueueType *q){return((q - rear + 1) % MAX_QUEUE_SIZE == q - front);}int is_full2(QueueType *q){return((q - rear + 1) % MAX_QUEUE_SIZE == q - front);}void enqueue(QueueType *q, element item){if (is_full(q)){error(큐가 포화상태입니다);}q - rear = (q - rear + 1) % MAX_QUEUE_SIZE;q - queue [q - rear] = item;que_count++;}void enqueue2(QueueType *q, element item){if (is_full2(q)){error(큐가 포화상태입니다);}q - rear = (q - rear + 1) % MAX_QUEUE_SIZE;q - queue [q - rear] = item;que_count2++;}element dequeue(QueueType *q){if (is_empty(q)){error(큐가 공백상태입니다);}q - front SPAont = (q - front + 1) % MAX_QUEUE_SIZE;que_count--;return q - queue [q - front];}element dequeue2(QueueType *q){if (is_empty(q)){error(큐가 공백상태입니다);}q - front = (q - front + 1) % MAX_QUEUE_SIZE;que_count2--;return q - queue [q - front];}element peek(QueueType *q){if (is_empty(q)){error(큐가 공백상태입니다);}return q - queue[(q - front + 1) % MAX_QUEUE_SIZE];}element peek2(QueueType *q){if (is_empty2(q)){ers=de1error(큐가 공백상태입니다);}return q - queue[(q - front + 1) % MAX_QUEUE_SIZE];}int is_customer_arrived(){if (random() arrival_prob){return TRUE;}else return FALSE;}int insert_customer(int arrival_time){element customer;int service=0;customer.id = customers++;customer.arrival_time = arrival_time;customer.service_time = (int)(max_serv_time * random()) + 1;service=customer.service_time;enqueue(&queue, customer);Setcolor(15,1);printf_s(-------------------------------------------\n);Setcolor(15,9);printf_s(고객 %d씨가 %d분에 들어오셨습니다.\n, customer.id, customer.arrival_time);Setcolor(15,12);printf_s(필요한 서비스 시간은 %d분입니다.\n, customer.service_time);printf_s(서비스 담당자는 직원 1 입니다.\n);printf_s(대기열1에 있는 고객수 %d명\n,check_que(que_count));printf_s(대기열2에 있는 고객수 %d명\n,check_que2(que_count2));Setcolor(15,1);printf_s(-------------------------------------------\n\n\n);service=service+1;return service;}int insert_customer2(int arrival_time){element customer;int service=0;customer.id = customers++;customer.arrival_time = arrival_time;customer.service_time2 = (int)(max_serv_time * random()) + 1;service = customer.service_time2;enqueue2(&queue, customer);Setcolor(15,1);printf_s(-------------------------------------------\n);Setcolor(15,9);printf_s(고객 %d씨가 %d분에 들어오셨습니다.\n, customer.id, customer.arrival_time);Setcolor(15,12);printf_s(필요한 서비스 시간은 %d분입니다.\n, customer.service_time2);printf_s(서비스 담당자는 직원 2 입니다.\n);printf_s(대기열1에 있는 고객수 %d명\n,check_que(que_count));printf_s(대기열2에 있는 고객수 %d명\n,check_que2(que_count2));Setcolor(15,1);printf_s(-------------------------------------------\n\n\n);service=service+1;return service;}int stand_by_time(int endtime, int arrivedtime, int servicetime){// 대기시간 = 종료시간 - (도착시간+서비스시간)int result=0;result = endtime-(arrivedtime+servicetime);return result;}intint remove_customer(int clock_temp_){element customer;if (is_empty(&queue)){return 0;}customer = dequeue(&queue);served_customers++;Setcolor(15,9);printf_s(고객 %d씨가 %d분에 서비스를 끝냈습니다.\n, customer.id, clock_temp);Setcolor(15,12);printf_s(고객 %d씨의 대기시간은 %d분이었습니다.\n, customer.id, stand_by_time(clock_temp_,customer.arrival_time,customer.service_time));return customer.service_time;}int remove_customer2(int clock_temp_){element customer;int service_time2=0;if (is_empty2(&queue)){return 0;}customer = dequeue2(&queue);service_time2 = customer.service_time2;served_customers++;Setcolor(15,9);printf_s(고객 %d씨가 %d분에 서비스를 끝냈습니다.\n, customer.id, clock_temp);Setcolor(15,12);printf_s(고객 %d씨의 대기시간은 %d분이었습니다.\n, customer.id, stand_by_time(clock_temp_,customer.arrival_time,customer.service_time));return service_time2;}void print_stat(void){Setcolor(15,9);printf_s(서비스 받은 고객수 = %d\n, served_customers);Setcolor(15,1);printf_s(전체 대기 시간 = %d분\n, waited_time);Setcolor(15,2);printf_s(1인당 평균 대기 시간 = %.2f분\n, (double)waited_time / served_customers);Setcolor(15,12);printf_s(아직 대기중인 고객수 = %d\n, customers - served_customers);}int main(void){int service_time = 0;int service_time2 = 0;clock_temp=0;system(color f0); //배경 흰색 글자 검정색fflush(stdin);srand((unsigned int)time(NULL)); //시스템의 시간 값을 이용하여 랜덤하게while(clock_temp duration){clock_temp++;Setcolor(15,1);printf_s(현재시각 = %d\n, clock_temp);if (is_customer_arrived()){if (que_count=que_count2){service_time=insert_customer(clock_temp);}else if (que_countque_count2){service_time2=insert_customer2(clock_temp);}}if (service_time 0){service_time--;}if (service_time == 0){service_time=remove_customer(clock_temp);}if (service_time2 0){service_time2--;}if (service_time2 == 0){service_time2 = remove_customer2(clock_temp);}}print_stat();_getch();return 0;}

신청하기





COMMENT

댓글을 입력해주세요. 비속어와 욕설은 삼가해주세요.

번호 제 목 글쓴이 날짜
2699555 c언어 다항식을 입력을 했는데 왜 출력이 안될까요? 피스케스 2025-06-27
2699528 C언어 포인터연산 질문입니다. (3) 안녕나야 2025-06-26
2699476 끌어올림;;달력 짜봤는데요 이 소스 줄일 수 있나요? - 스샷첨부 (2) 클라우드 2025-06-26
2699444 [좀 급함] system("explorer [주소] ") 문에 변수를 사용할 수 있나요? 알 2025-06-26
2699415 파일//read//와 배열 아란 2025-06-25
2699386 구조체 안에 일부분만 char 배열에 복사하려면 어떻게 해야하나요? (1) 미즈 2025-06-25
2699361 연결리스트 정렬하는 부분에 대해서 질문 드립니다 아이처럼 2025-06-25
2699304 [기초]아직 안주무시는분 계신가요..?포인터배열? 좀 도와주세요. 놀리기 2025-06-24
2699272 printf() 함수이용해서 프로그램 만들기 질문요! (5) 다가 2025-06-24
2699221 PUSH와 POP코드를 더 간단하게 어떻게 해야할까요? 파라미 2025-06-24
2699192 설치오류가 자꾸 나요 한번봐주세여~ (1) 소녀틳향기 2025-06-23
2699161 for loop안에 있는 if문 (9) Orange 2025-06-23
2699105 링크더리스트 이전 링크값 출력함수. 꼬꼬마 2025-06-23
2699078 정수를 한자리씩 배열에 담는 법은 어떻게 하나요.. (4) 귀염포텐 2025-06-22
2699024 C언어 공부하려는데 도와주세요!!! (2) 달님 2025-06-22
2698994 날짜 계산하는 C 코드 짜고 있는데 꽉 막혀서 질문드립니다.. (6) 별 2025-06-22
2698967 파일삭제 윈도우 폴더까지 접근하게하는 함수가 뭔가요 (2) 샤인 2025-06-21
2698938 c언어 메모리질문 (3) 나래 2025-06-21
2698909 서비스 요청 고객 관리 프로그램 짜는것좀 도와주세요ㅜㅜ (4) 궁수자리 2025-06-21
2698882 프로그래밍좀 짜주세요 (3) 황예 2025-06-21
<<  이전  1 2 3 4 5 6 7 8 9 10  다음  >>

수다닷컴 | 여러분과 함께하는 수다토크 커뮤니티 수다닷컴에 오신것을 환영합니다.
사업자등록번호 : 117-07-92748 상호 : 진달래여행사 대표자 : 명현재 서울시 강서구 방화동 890번지 푸르지오 107동 306호
copyright 2011 게시글 삭제 및 기타 문의 : clairacademy@naver.com