พบกับบทความเกี่ยวกับคอมพิวเตอร์และ programming ได้ที่ http://articles.modoeye.com
C programming / ดูcode ใหหน่อยครับ
โออ
โออ
Mon 28 Aug 2006 23:51:39
#include <stdio.h>
#include <conio.h>
void main(void){
 int choice,sale[20],bonus[20],n,i;
 float tsale,tbonus;
 char name[20][20];
 for(;;){
 choice=menu();
 clrscr();
 if(choice==1){
  printf("How many people::");
  scanf("%d",&n);
  clrscr();
  printf("No.");
  gotoxy(15,1); printf("Employee's Name");
  gotoxy(35,1); printf("Sale amount\n");
  for(i=0;i<n;i++){
   printf("%2d.",i+1);
   gotoxy(8,i+2); scanf("%s",name[i][20]);   /*เวลารับค่า name ยาว ๆ มันจะกระโดดไปเลยไม่ยอมรับค่า sale ครับ แก้ยังไงดีครับ*/
   gotoxy(40,i+2);scanf("%d",&sale[i]); 
   }
  }
 else if(choice==2){
  printf("Press any key to start calculate...");
  getch();
  for(i=0;i<n;i++){
   tsale+=sale[i];
   if(sale[i]>=10000)
    bonus[i]=sale[i]*0.05;
   else if(sale[i]>=25000)
    bonus[i]=sale[i]*0.10;
   tbonus+=bonus[i];
   }
  printf("\nReturn to main menu... Press any key...");
  getch();
  }
 else if(choice==3){
  printf("No.");
  gotoxy(15,1); printf("Employee's Name");
  gotoxy(35,1); printf("Sale amount");
  gotoxy(50,1); printf("Bonus amount\n");
  for(i=0;i<n;i++){
   printf("%2d.",i+1);
   gotoxy(8,i+2); printf("%s",name[i]);
   gotoxy(38,i+2);printf("%d",sale[i]);
   gotoxy(55,i+2);printf("%d\n",bonus[i]);
   }
  getch();
  }
 else if(choice==4){
  printf("Total sale=%9.2f\n",tsale);
  printf("Total bonus=%9.2f\n",tbonus);
  printf("\nPress any key to return to main menu...");
  getch();
  }
 else if(choice==0){
  printf("Press any key to exit program");
  getch();
  exit();
  }
 }
 }
menu(){
 char left=218,left2=192,right=191,right2=217,tri=195,tri2=180,
 hori=196,vert=179,i;
 int choice;
 clrscr();
 gotoxy(20,18); printf("%c",left);
 for(i=1;i<39;i++)
  printf("%c",hori);
 printf("%c",right);
 gotoxy(20,19); printf("%c",vert);
 gotoxy(59,19); printf("%c",vert);
 gotoxy(20,20); printf("%c",tri);
 for(i=1;i<39;i++)
  printf("%c",hori);
 gotoxy(59,20); printf("%c",tri2);
 for(i=1;i<13;i++){
  gotoxy(20,i+20); printf("%c",vert);
  gotoxy(59,i+20); printf("%c",vert);
  }
 gotoxy(20,33); printf("%c",left2);
 for(i=1;i<39;i++)
  printf("%c",hori);
 printf("%c",right2);
 gotoxy(30,19); printf("M A I N - M E N U");
 gotoxy(21,21); printf("1. Input salesman data.");
 gotoxy(21,23); printf("2. Calculate data.");
 gotoxy(21,25); printf("3. Display salesman data and bonus.");
 gotoxy(21,27); printf("4. Display total sale and total bonus.");
 gotoxy(21,29); printf("0. Exit program.");
 gotoxy(21,32); printf("Please select menu item(1-4)::");
 scanf("%d",&choice);
 return choice;
 }
Administrator
Tue 29 Aug 2006 02:07:55
ไม่ได้จับนานแล้วคุณลองทำการจองตัวแปร name ให้รองรับได้ยาวมากขึ้นดูหรือยังครับ เท่าที่ดูจองไว้เพียง 20 ตัวอักษรเท่านั้น
คนไม่เก่งคอม
คนไม่เก่งคอม
Mon 4 Sep 2006 02:41:36

ขอโทษครับพอจะมีโปรแกรม อะไรยาวๆซัก 200 บรรทัดไหมครับ

ถ้ามีช่วยกรุณาลงไว้ให้จะเป็นพระคุณอย่างมากครับ ขอบคุณครับ

Administrator
Mon 4 Sep 2006 09:01:22
ไม่ได้เขียนนานมากแล้วล่ะครับ ลองค้นๆดูก็เจอ
http://www.cis.temple.edu/~ingargio/cis71/code/
เป็นโปรแกรมง่ายๆที่เขียนด้วย c ซึ่งแต่ละอันก็จะยาวประมาณ 20-50 บรรทัด
หรือจะลองเล่นกับพวกไฟล์เช่น
http://www.daniweb.com/techtalkforums/thread40746.html

อาจจะทำโปรแกรมที่รับค่ามาแล้วเขียนลงไฟล์เป็น ฐานข้อมูลแบบง่ายๆ แล้วอาจจะดึงข้อมูลเหล่านั้นมาวิเคราะห์ หาค่าเฉลี่ย ฯลฯ
คนไม่เก่งคอม
คนไม่เก่งคอม
Tue 5 Sep 2006 13:18:52

ขอบคุณมากครับที่ช่วยแนะนำ

Reply
Name:
E-mail:
Home | Services | Forum | Classified | Directories | Support | Contact
ATOM feed RSS 0.9 feed RSS 1.0 feed RSS 2.0 feed
Copyright © 2005 - 2007 Modoeye.com, All Rights Reserved.
Disclaimer | Privacy policy | Term of Use | Term of Services
Valid XHTML Valid CSS! PHP: Hypertext Preprocessor MySQL database Apache Powered! FreeBSD Power to serve
Modoeye Sitemap Client login