第二题:
/*大学里对不同性质的学生听课收费不同。某校是这样规定的:本校全日制学生不收费;
本校夜大学生选课12学分及以下付200元,然后每增加一个学分付20元;
对外校学生选课12学分及以下付600元,然后每增加一个学分付60元。
输入某个学生的编号,选课学分以及学生类型,编程计算该学生应付的学费 */
#include <stdio.h>
int WorkCost(int ,int );
void main()
{
char studentId[20];
int studentCreditHour,studentType;
int cost;
printf("Input the Student ID:");
scanf("%s",studentId);
printf("Input the [%s] Credit Hour:",studentId);
scanf("%d",&studentCreditHour);
printf("Input the [%s]\nType(1 is this school,2 is evening university,3 is others):",studentId);
scanf("%d",&studentType);
cost=WorkCost(studentCreditHour,studentType);
printf("[%s] is cost : %d\n",studentId,cost);
}
int WorkCost(int studentCreditHour,int studentType)
{
switch ( studentType )
{
case 1:
return 0;
case 2:
if ( studentCreditHour <= 0 )
{
return 0;
}
else if ( studentCreditHour <= 12 )
{
return 200;
}
else
{
return 200 + (studentCreditHour - 12) * 20;
}
case 3:
if ( studentCreditHour <= 0 )
{
return 0;
}
else if ( studentCreditHour <= 12 )
{
return 600;
}
else
{
return 200 + (studentCreditHour - 12) * 60;
}
default:
return 0;
}
}