promotion image of download ymail app
Promoted

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

求手機每月費用....打ㄉ分鐘數用鍵盤輸入

1~10分鐘..每分2元

11~20分鐘..每分1.5元

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

意思是說譬如我這ㄍ月總共打ㄌ100分鐘...這100分鐘ㄉ前10分鐘每分算2元...到11~20分鐘期間每分算1.5元....21分鐘以後一直用每分四元計算到100分鐘....以這樣ㄉ條件求總共費用.....慢慢ㄉ推下去

2 Answers

Rating
  • 1 decade ago
    Favorite Answer

    #include <stdio.h>

    #include <stdlib.h>

    int main()

    {

    int total, sum;

    do{

    printf("please input the total time:");

    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;

    }

    • Commenter avatarLogin to reply the answers
  • 1 decade ago

    #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;

    }

    • Commenter avatarLogin to reply the answers
Still have questions? Get your answers by asking now.