MUstar

IoT C언어 0626 - ex_01_2

Jun 26th, 2017
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.77 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4.  
  5. int menu(void);
  6. void print_graph(char name[20], int *ps, int size, int cnt, int num);
  7.  
  8. struct graph{
  9.     char name[20];
  10.     int score;
  11. };
  12. struct graph table[]; //일단 무제한(?), Warning....
  13. int main(void)
  14. {
  15.     menu();
  16.     printf("프로그램을 종료합니다.\n");
  17.     return 0;
  18. }
  19.  
  20. int menu(void)
  21. {
  22.     int cnt=0, temp_num;
  23.    
  24.     while(1){
  25.         int sele;
  26.         printf("점수그래프출력프로그램v1\n");
  27.         printf("1)입력 2)출력 3)종료\n");
  28.         scanf("%d", &sele);
  29.         if (sele==1){
  30.             printf("이름와 점수를 입력하세요. 구분은 뛰어쓰기입니다.\n");
  31.             printf("예)최나나 950 //||//■■■■■■■■■■■■■■■■■■■■■■■■■■■■\n");
  32.             printf("--------------------------------------------------\n");
  33.             printf(">");scanf("%s%d",table[cnt].name, &table[cnt].score);
  34.             cnt++;
  35.         }
  36.         else if(sele==2){
  37.             for(int i= 0;i<cnt;i++)
  38.             {
  39.                 char *user_name = table[i].name;
  40.                 int score_num = table[i].score;
  41.                 int graph_num = score_num / 5;
  42.                 print_graph(user_name,&score_num,graph_num,cnt,i);
  43.             }  
  44.         }
  45.         else if(sele==3) break;
  46.         else if(sele==4) printf("%d|%s|%d\n",cnt-2,table[cnt-1].name, table[cnt-1].score); //입력확인용 선택
  47.         else printf("잘못입력했습니다. 다시입력하세요.");
  48.     }
  49. }
  50.  
  51. void print_graph(char name[20], int *ps, int size, int cnt, int num)
  52. {
  53.     int mm = *ps - (*ps/10*10);
  54.     if (mm>=5){if(mm-5>2) mm=1; else mm=0;} else {if(mm>2) mm=1; else mm=0;}
  55.     int size_p = size + mm;
  56.    
  57.     printf("%s|",name);
  58.     if(*ps<10)printf("|  %d|",*ps);
  59.     else if(*ps<100)printf("| %d|",*ps);
  60.     else printf("|%d|",*ps);
  61.    
  62.    
  63.     for(int i=0;i<size_p;i++)
  64.     {
  65.         printf("*");
  66.         //printf("■");
  67.     }
  68.     printf("|\n");
  69. }
Add Comment
Please, Sign In to add comment