# C語言程式作業求........急20點...算手機費用

1~10分鐘..每分2元

11~20分鐘..每分1.5元

21分鐘以上..每分4元.

Rating

#include <stdio.h>

#include <stdlib.h>

int main()

{

int total, sum;

do{

scanf("%d", &total);

if( total > 100 ) printf("can't over 100\n");

}while(total > 100);

sum = 0;

if( total <= 10) sum = total * 2;

else if( total <= 20){

sum = 10 * 2 + ( total - 10 ) * 1.5;

}else sum = 10 * 2 + 10 * 1.5 + ( total - 20 ) * 4;

printf("money：%d\n", sum);

system("PAUSE");

return 0;

}

#include <stdio.h>

#include <stdlib.h>

int main()

{

double cost[] = { 2 , 1.5 , 4 } ;

double totalCall = 0 , totalCost = 0 ;

printf("請輸路通話時間：");

scanf( "%le" , &totalCall );

if ( totalCall <= 0.0 )

{

printf("無通話費用！\n");

return 0 ;

}

else

{

if ( totalCall - 10.0 <= 0 )

totalCost = totalCall * cost[0] ;

else if ( totalCall - 20.0 <= 0 )

totalCost = 10 * cost[0] + (totalCall-10) * cost[1];

else

totalCost = 10 * cost[0] + 10 * cost[1] + (totalCall-20) * cost[2] ;

}

printf("通話費用 = %.2f\n" , totalCost );

system("PAUSE");

return 0;

}