|
 |
|
รบกวนถาม ภาษา C พื้นฐานเล็กๆน้อยๆหน่อยค้าบ #include <stdio.h> #include<conio.h> void main() |
|
 |
|
|
 |
 |
|
#include <stdio.h>
#include<conio.h>
void main()
{
char id[11],name[30],surname[30],gender[2],depart[40];
int day,month,year,age;
float weight,height,bmi;
clrscr();
printf("Enter ID: ");
scanf("%s",&id);
printf("Enter First Name: ");
scanf("%s",&name);
printf("Enter Last Name: ");
scanf("%s",&surname);
printf("Enter Birthday(dd/mm/yyyy): ");
scanf("%d%d%d",&day,&month,&year);
printf("Enter Sex: ");
scanf("%s",&gender);
printf("Enter Department: ");
gets(depart);
printf("Enter your weight (kilograms): ");
scanf("%f",&weight);
printf("Enter your height (centimeters): ");
scanf("%f",&height);
age = 2010 - year;
bmi = (height*height)/weight;
printf("+----------------====Airbon====----------------+\n");
printf("+\t\t My Profile \t\t +\n");
printf("+\t\t ------------ \t +\n");
printf("+\tName: %s %s",name,surname);
printf(" \t\t +\n");
printf("+\tID: %s",id);
printf("\t\t\t +\n");
printf("+\tAge: %d years old, Sex: %s",age,gender);
printf("\t +\n");
printf("+\tDepartment: %s",depart);
printf(" \t+\n");
printf("+ \t\t\t\t\t +\n");
printf("+ \t\t\t\t\t +\n");
printf("+----------------====Airbon====----------------+\n");
printf("+ \t\t\t\t\t +\n");
printf("+\tBody Mass Index (BMI) = %.2f",bmi);
printf(" +\n");
printf("+ \t\t\t\t\t +\n");
printf("+----------------====Airbon====----------------+\n");
getch();
}
ภาษา C นะครับคือมีปัญหาตรง
printf("Enter Sex: ");
scanf("%s",&gender);
printf("Enter Department: ");
gets(depart);
printf("Enter your weight (kilograms): ");
scanf("%f",&weight);
พอหลังรับค่า Enter Sex: M เสร็จปุ้บ แทนที่มันจะขึ้นให้ใส่ Depart ต่อมันกลายเป็นแบบนี้เลยอะ
Enter Department: Enter your weight (kilograms): I
ทีนี้พอผมลองแก้เป็น
printf("Enter Department: ");
gets(depart);
gets(depart);
หรือ
gets(depart);
printf("Enter Department: ");
gets(depart);
มันดันรับค่าได้ซะงั้นแต่ผมรู้สึกว่ามันผิดหลักการเขียนใช่มะ - -? แล้วพอไปลบไอพวกรับค่าอันอื่นออกหมด จนเหลือแต่ Depart รัน ต่อให้มี gets อันเดียวมันก็รับค่าได้ไม่กระโดดข้ามเหมือนตอนรันทั้งชุดอะ ใครพอจะทราบวิธีแก้มั่งครับ- -? ขอบคุณมากคับ แบบผมจนปัญญาแล้ว-*-
Tag : - - - -

|
|
 |
 |
 |
 |
Date :
2010-06-25 09:45:09 |
By :
airbon |
View :
2373 |
Reply :
1 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
มันรับ enter มาจากตัวที่แล้วน่ะสิ จะดักด้วย getch() ก็ได้
แล้วทำไมไม่ใช้ scanf เหมือนตัวอื่นล่ะ
|
 |
 |
 |
 |
Date :
2010-06-25 11:03:19 |
By :
tungman |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 05
|