คือเขียนโค้ดคำสั่ง swicht case แล้วต้องรับค่ารหัสนักศึกษา xxxxxxxxxxx-x ประมาณนี้ แต่ลองใช้ int หรือ long หรือ long in แล้วมันไม่แสดงผลลัพธ์ตามที่พิมพ์ไปค่ะ ช่วยแก้หน่วยค่ะ ไม่รู้จะแก้ยังไงแล้วเพราะต้องส่งพรุ่งนี้ ติดแค่ตรงนี้ที่เดียว
โค้ดค่ะ
#include<stdio.h>
int main(){
int code; << ติดตรงนี้
char name[50];
char lastname[50];
char faculty;
int type;
float net;
float discount;
float tuitionfee;
printf("Enter Code : ");
scanf("%d",&code);
printf("\nEnter Name : ");
scanf("%s",&name);
printf("\nEnter Last Name : ");
scanf("%s",&lastname);
printf("\nEnter Faculty : ");
scanf("%s",&faculty);
printf("\nEnter Type : ");
scanf("%d",&type);
printf("------------------------------------------------\n");
switch(faculty){
case 'E':
if(type == 1){
tuitionfee = 25000.00;
discount = tuitionfee * (float)10/100;
net = tuitionfee + discount;
}
else if(type == 2){
tuitionfee = 50000.00;
discount = tuitionfee * (float)10/100;
net = tuitionfee + discount;
}
printf("Code : %d \n", code);
printf("Name : %s \n", name);
printf("LastName : %s \n",lastname);
printf("Faculty : Engineering \n");
printf("Type : %d \n", type);
printf("Tuition Fee : %.2f \n",tuitionfee);
printf("Discount : %.2f \n", discount);
printf("Net : %.2f \n", net);
break;
case 'M':
if(type == 1){
tuitionfee = 25000.00;
discount = tuitionfee * (float)10/100;
net = tuitionfee + discount;
}
else if(type == 2){
tuitionfee = 50000.00;
discount = tuitionfee * (float)10/100;
net = tuitionfee + discount;
}
printf("Code : %d \n", code);
printf("Name : %s \n", name);
printf("LastName : %s \n", lastname);
printf("Faculty : Medicine \n");
printf("Type : %d \n", type);
printf("Tuition Fee : %.2f \n",tuitionfee);
printf("Discount : %.2f \n", discount);
printf("Net : %.2f \n", net);
break;
case 'S':
if(type == 1){
tuitionfee = 25000.00;
discount = tuitionfee * (float)10/100;
net = tuitionfee + discount;
}
else if(type == 2){
tuitionfee = 50000.00;
discount = tuitionfee * (float)10/100;
net = tuitionfee + discount;
}
printf("Code : %d \n", code);
printf("Name : %s \n", name);
printf("LastName : %s \n", lastname);
printf("Faculty : Science \n");
printf("Type : %d \n", type);
printf("Tuition Fee : %.2f \n",tuitionfee);
printf("Discount : %.2f \n", discount);
printf("Net : %.2f \n", net);
break;
default :
printf("Code : %d \n", code);
printf("Name : %s \n", name);
printf("LastName : %s \n", lastname);
printf("Faculty : Invalid Faculty ");
printf("Type : InvalidType ");
printf("Tuition Fee : %.2f \n",tuitionfee);
printf("Discount : %.2f \n", discount);
printf("Net : %.2f \n", net);
}
}
ช่วยแก้โค้ดภาษาซี หน่อยค่ะ
โค้ดค่ะ
#include<stdio.h>
int main(){
int code; << ติดตรงนี้
char name[50];
char lastname[50];
char faculty;
int type;
float net;
float discount;
float tuitionfee;
printf("Enter Code : ");
scanf("%d",&code);
printf("\nEnter Name : ");
scanf("%s",&name);
printf("\nEnter Last Name : ");
scanf("%s",&lastname);
printf("\nEnter Faculty : ");
scanf("%s",&faculty);
printf("\nEnter Type : ");
scanf("%d",&type);
printf("------------------------------------------------\n");
switch(faculty){
case 'E':
if(type == 1){
tuitionfee = 25000.00;
discount = tuitionfee * (float)10/100;
net = tuitionfee + discount;
}
else if(type == 2){
tuitionfee = 50000.00;
discount = tuitionfee * (float)10/100;
net = tuitionfee + discount;
}
printf("Code : %d \n", code);
printf("Name : %s \n", name);
printf("LastName : %s \n",lastname);
printf("Faculty : Engineering \n");
printf("Type : %d \n", type);
printf("Tuition Fee : %.2f \n",tuitionfee);
printf("Discount : %.2f \n", discount);
printf("Net : %.2f \n", net);
break;
case 'M':
if(type == 1){
tuitionfee = 25000.00;
discount = tuitionfee * (float)10/100;
net = tuitionfee + discount;
}
else if(type == 2){
tuitionfee = 50000.00;
discount = tuitionfee * (float)10/100;
net = tuitionfee + discount;
}
printf("Code : %d \n", code);
printf("Name : %s \n", name);
printf("LastName : %s \n", lastname);
printf("Faculty : Medicine \n");
printf("Type : %d \n", type);
printf("Tuition Fee : %.2f \n",tuitionfee);
printf("Discount : %.2f \n", discount);
printf("Net : %.2f \n", net);
break;
case 'S':
if(type == 1){
tuitionfee = 25000.00;
discount = tuitionfee * (float)10/100;
net = tuitionfee + discount;
}
else if(type == 2){
tuitionfee = 50000.00;
discount = tuitionfee * (float)10/100;
net = tuitionfee + discount;
}
printf("Code : %d \n", code);
printf("Name : %s \n", name);
printf("LastName : %s \n", lastname);
printf("Faculty : Science \n");
printf("Type : %d \n", type);
printf("Tuition Fee : %.2f \n",tuitionfee);
printf("Discount : %.2f \n", discount);
printf("Net : %.2f \n", net);
break;
default :
printf("Code : %d \n", code);
printf("Name : %s \n", name);
printf("LastName : %s \n", lastname);
printf("Faculty : Invalid Faculty ");
printf("Type : InvalidType ");
printf("Tuition Fee : %.2f \n",tuitionfee);
printf("Discount : %.2f \n", discount);
printf("Net : %.2f \n", net);
}
}