1 like 0 dislike
21.6k views

A water supply company charges the water consumption, as follows:

a) Fixed amount of 10$.
b) For the first 30 cubic meters 0.6$/meter.
c) For the next 20 cubic meters 0.8$/meter.  
d) For the next 10 cubic meters 1$/meter.  
e) For every additional meter 1.2$/meter.   

Write a program that reads the water consumption in cubic meters and displays the bill.
寫一個輸入水的用量 輸出水費的程式

Example Input:

25

Output:

Cost: 25.00

Example Input 2:

44

Output:

Cost: 39.20

Example Input 3:
 

75

Output:

Cost: 72.00

 

[Exercise] Coding (C) - asked in Chapter 4: Expressions by (12.1k points)
ID: 26465 - Available when: Unlimited - Due to: Unlimited

edited by | 21.6k views

91 Answers

0 like 0 dislike
Hidden content!
#include * ** * ***

int main()

{
** * *** ***** ** ** * n,sum;
*** **** * * * *** *** *** * * *** * ** *

*** ** * * * * ** **** * (n<=30)
** ** * **** ** * **** *** *
* * ******* *** ** * ***** * * %.2f",sum);}

*** *** ** * * ** * * * if (n<=50)
* ** * * * * * ** * *** *** ***
***** * * *** * ** * *** * * * %.2f",sum);}

***** * **** ** * * * ** if (n<=60)
* * *** * ** * ** * **** * * * *** * *** * *
** * ***** * ** *** * **** * * %.2f",sum);}

*** * * * *** * ** * *
** ** *** ** **** * * ** * ** * *** ***
* * ***** ** **** * *** ** ** %.2f",sum);}

** * ** ** *** ** ** * 0;

}
answered by (-249 points)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
Case 4: Correct output
0 like 0 dislike
Hidden content!
#include <stdio.h>

int main()
{
** * **** * *** *** wc;
***** * * *** * * * * total=0;
* * *** *** * **** tab1;
* ** * ** *** ** *** * *** tab2;
* * * * * ** ** ** ** *** nt1;
** *** ** * * nt;
 
* * ** * *** **** ** ** * ** *** ***** ** **
    
** * ** ** * * **** * (wc<30)
    {
* *** *** * *** **** * *** **** *** *** * ** *
    }
    
*** ** ** ** ** ***** * *** ** * ** ** * * * * ** *
** ******** ***** ** * *
* ** ***** * ** * * ** * ** ** ** *** ** ** * *
* * * * ** * * **** * ** ** * *** * * ** **
**** * * *** * * ****** * * * ** * * (nt>20)
** * * * ** ** * ** *** ** * ** * ** ** **** * **
** * ** * ** ** ** * * * ***** ****** *** * ** **** *** * ** * ** *
* ** * * ** **** ** * * * * * * * ***
**** * * * *** * ** ** * ** * * * * ***** *** * *
* *** * * * ** ** * ** * ** ** **** * * ***
* ** * **** ****** *** *** ** * * **** * * *** * * * * **** * ***
* * * ** ** *** * ** * ** ** *** ****
* * ******** ***** * * * **** ** * *** * **
    }
    
* * * *** ******* * ** ** *** ** ****
* * * **** *** **** * * **** * **
** * * * *** **** ******* * * **** ** * * ****** * * * * * *
** **** ****** ****** ** * * ****** *** * ****** * ** ******* *** **** ** ***
* *** *** ****** ** **** * **** **** *
    
* **** * * ** * ** * * ** ***** * *** %.2f",total);
   
** * ***** * *** * *** 0;
}
answered by (-193 points)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
Case 4: Correct output
0 like 0 dislike
Hidden content!
#include <stdio.h>

int main()
{
* * * * * * * * ****** * wc;
* * ** ** ** * ** * total=0;
** * * ** * ** * tab1;
** *** *** ***** ** * ** ** tab2;
* * **** ** * * * nt1;
** * * ** ** * * ** ** ** nt;
 
** ** *** * *** ** *** * ** ** * ** ** ** ****
    
* * * **** **** * ** * (wc<30)
    {
** * * ** * ** ** * * **** * * * * * ** * *
    }
    
* * * * **** *** *** *** * * ** **** * * **** ** ** **
    {
** * * * **** ** * ****** **** ** * ***** ****** *
** ** * * * ** *** ***** * ** * * * ** *
* * *** ******* * * *** ** ******* * * ** ** ******* * (nt>20)
* * * ** ** * * ** ** ** * ******* *
* *** * * * * ***** * * *** ** * *** ** * *** *** *** ** ***** * ** ** * * * * ***
** ** ** * ** **** * * * * ** *
** * * * * ** * * * * ** * * *** ***
**** ** **** * ** **** **** * ** ** * * *
* ** * * *** * ** **** * * *** **** ** ** ** ********** ****
*** * *** ** *** ** * * *** * **
* *** *** * ** **** * * * * * * *** *** * *
    }
    
* * *** * * * * * * ** ** * * * *
** * * *** ** * * * * * ** ** *
* ** *** * **** **** * *** **** * * * ** * * ** *** *
** **** * **** ** ** ** * ** * * * * ** * *** * *** ** * *** **** **** *
** * * * * * *** * * * * * **
    
* ** * ***** * ** ** ** **** ** ******* *
   
** * ** ** ** ** * ** * *** 0;
}
answered by (-193 points)
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
Case 3: Wrong output
Case 4: Wrong output
0 like 0 dislike
Hidden content!
#include <stdio.h>

int main()
{
* ** * *** * * ***** * ** ** wc;
** ** * * ** * **** * total=0;
** * * * * *** *** tab1;
*** ** ** ** ********* ** * tab2;
** ** ** * ** * * nt1;
**** * * * * **** ** * nt;
 
* *** *** ** **** * * * **** * *
    
*** ** * * * * * ** (wc<30)
    {
*** * * ** *** * * **** ** ** * ***** * * * ** * * ** **
    }
    
* **** * * * * ** *** ** * * * * * * *** *
    {
* * *** * * * * * * *** * * * *** * * *** * * *** *** **
* * *** *** * ***** ** * **** ** * * *** ** * *
* * ** * * ** ** *** ** ** ***** * ** * * * ** *** (nt>20)
* * * *** *** *** ******* ***** ** *
* * * ** *** ** * * **** * * * ** * *** * * *** ** * ****** ** ***** **
** ***** * ** * * ******* *** * * ** * **
**** * **** * *** *** ******** ** *** * ** ***
* * * * **** ** **** ** * *
* **** * * ** ***** * **** * * **** * ** * ** * ** ** ****** ** **
*** ** ** * * * **** ***** * *** *** * *
** * ***** ** ** ** * * * ** *** * * *** **** * **
    }
    
* ** *** **** *** ** ** * ** * * ** **
* * * * ** ** ** ** * ***
*** *** ** * ** *** ** **** **** * * * ** *** * * * * * ** *
* ** * * * * * *** * ***** ** * * * * * **** ** * **** * * * ** *
* * * *** ** ******** ** *** *
    
* * ** * ** * *** ** * ** * ** * *** * *
   
* * * * **** * * ** 0;
}
answered by (-193 points)
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
Case 3: Wrong output
Case 4: Wrong output
0 like 0 dislike
Hidden content!
#include <stdio.h>

int main()
{
** * * ** * ** * ** ** unit;
*** ** * * * * * ** *** * ******** * ** *** total_amt, net;
** * * * *** *** **
** * * ** * *** * * ** *** * * &unit);
***** * *** * ** * *
* **** * *** ** *
* * * *** * * * * * * * * ** ** * <= 30)
** ** * ** * * *****
* * * * * ***** ***** ********* * * = unit * 0.60;
* * * *** ** * * * *
* * *** ***** ***** * **
***** * * * ** ** * *** ** * if(unit <= 50)
* ** * ** ** **** ** *** *
** ***** **** * * * **** ******* *** * * * = 18 + ((unit-30) * 0.80);
* ************ * ****** *
* ** * * * * ** ** ** if(unit <= 60)
** * ** ** ** *** **
** ** **** * * * * * * * * ***** = 38 + ((unit-50) * 1.00);
* * * ** * * *** *** *
**** * ******** ** * ** ** if (unit >60)
** * ****** ** * ***
* * *** ** * *** * * * * ** * * ** * * =  44 +((unit-60)*1.20);
** * ** *** *** **
* * * *** **** ** *
* *** **** * ***** ** ** * = amt1+amt2+amt3+amt4;
** ***** ** * * * **
* *** * * * ***
* * * ***** ***** * ** *  = net+ 10.00;
* * ** *** **
* ** *** * * **** **** ***** %.2f", total_amt);
* ***** **** **** ** *
** **** * *** *** * * 0;
}
answered by (323 points)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
Case 4: Correct output
0 like 0 dislike
Hidden content!
#include * **** *
int main ()
{
*** * ** * * * * * ** waterUsage;
** ** ** ** **** * * * * ** cost;

*** **** *** ***** ** * * * *** * ** *

** **** * * * * **** ** ** *** ** * *** * * * ** **
* ** * * * * *** *** *** *** * * ** * ** * * = (waterUsage * 0.6)+ 10;
** * ***** ** ** * * **** (waterUsage >=30 * * * *** * waterUsage <50)
* * * * * ** * **** * ** * * * * **** = ((waterUsage-30)* 0.8)+(30 * .6) + 10;
** * * ** ***** * ** ** * **** * * * ** **** * * *** * * **
** *** * *** * * ** * *** ** * * ** = * * * (30*.6) + (20*.8) +10;
* ** * * * * * *** * ** ***
* * * ** ** ** *** * * ** *** * *** = *** * * ** * * * *** + 10;
* ** **** * *** ***** * *** * %.2f", cost);

}
answered by (-167 points)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
Case 4: Correct output
0 like 0 dislike
Hidden content!
#include * ** *** * *
int main ()
{
* * * * * ** * * waterUsage;
* *** ** *** * ** * * cost;

** *** ** *** * * * *** * ** * ** *** **

* ******* ** ** * * * ** * * && * *** *** **
* * ** * * * * ** ** ** ** * *** * **** ****** = (waterUsage * 0.6)+ 10;
** ** *** * ** * * ** (waterUsage >=30 * ***** * waterUsage <50)
* *** * * ** ***** *** ** ** * ** * * * = ((waterUsage-30)* 0.8)+(30 * .6) + 10;
** * * * **** * *** **** *** ***** * ** * * ****** * *
** ******** * ******** ** **** ***** ***** * * = * *** * (30*.6) + (20*.8) +10;
** * ***** * ** *** * * *** ** *
** * * ****** * *** * * * * * * * * ** *** * = **** ** * * *** * *** ** + 10;
* ** ** * * ***** * * * * * * ** * cost);

}
answered by (-167 points)
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
Case 3: Wrong output
Case 4: Wrong output
0 like 0 dislike
Hidden content!
** ** * *** **
* ** ** ** ***

int main()
{
** ** * ** * * * ** a1;
** * * *** * *** * * *** * *** * ** * ** *
* ** * * ** *** *** < 30)
***** * * * ** ** * ** **** * * * * *** * * * *** * * **

* ** *** * * *** ** * * ** * if(a1 > ** * *** ** < 50)
* * * **** ***** ****** *** ****** **** ** * * ***** *** **** * ** ** * 0.6+(a1-30)*0.8)+10);

*** **** ** ** * **** * ** if(a1 > * * * ** ** * < 60)
** * ** * ** * * * **** * * * * * * * * * * ****** * * *** *** * * 0.6) + (20 *0.8)+(a1 - 50)*1+10);

* ** * ** ** * * **
* *** * * * * * * * * ** * ** ** ** * ******** ** * ** * ****** *0.8)+(30 *0.6)+10+(a1 - 60)*1.2+10);
** *** ** ******
return 0;
}
answered by (-141 points)
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
Case 3: Wrong output
Case 4: Wrong output
0 0
please remove all newline at the end, it makes your program have wrong output
0 like 0 dislike
Hidden content!
* * * * ** * *
** * ** * *** ** ***

int main()
{
* ** *** * * * ** * a1;
* * ** * ** * * ** **** ** * * * ** * *
***** **** * *** * * *** ** * ** < 30)
* ***** ** * ** ********* *** * **** **** **** **** *** *

* * * ** **** ** *** * *** if(a1 > * * ** * * < 50)
** *** * * **** ** * * * * * * *** * * * ** *** ***** * * ****** * *** * * **** *** * *

* * * *** * *** **** if(a1 > * * *** *** * < 60)
***** ** *** ** * * ** *** * * * ** * * * * * * ** %.2f\n",(30 * 0.6) + (20 *0.8)+(a1 - 50)*1+10);

*** * * ** *** * * ** *
** *** ** * * * ** ** ** *** * **** * * ** * * * ** *0.8)+(30 *0.6)+10+(a1 - 60)*1.2+10);
***** ** * * * * *
return 0;
}
answered by (-141 points)
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
Case 3: Wrong output
Case 4: Wrong output
0 like 0 dislike
Hidden content!
* ** * * **
* * * *** * * *

int main()
{
* * * * * ** *** * ** a1;
** ** * * *** * *** ****** * * * ** *** * ** * * *
**** * * * * * * < 30)
*** ************ ** ** * ** * * ** * * * * ** * ** * * ** * * *

*** * * * * if(a1 > *** * ** ** < 50)
*** ** ** * ** **** * ** *** * ** **** * * * *** * * * * * ** * * * ****** *** * *

** *** * * ** ** * if(a1 > * ** ***** < 60)
*** ** *** * ** ** * * * * * * * * * * * **** ** * ** %.2f\n",(30 * 0.6) + (20 *0.8)+(a1 - 60)*1+10);

**** * * ** * **
** **** *** * ** * * * ** * * * * *** * ** * *** ** **** * **** ** * *0.8)+(30 *0.6)+10+(a1 - 60)*1.2+10);
* * * * ** * * * * **
return 0;
}
answered by (-141 points)
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
Case 3: Wrong output
Case 4: Wrong output
Welcome to Peer-Interaction Programming Learning System (PIPLS) LTLab, National DongHwa University
English 中文 Tiếng Việt
IP:172.69.130.92
©2016-2025

Related questions

3 like 0 dislike
87 answers
[Exercise] Coding (C) - asked Oct 12, 2017 in Chapter 3: Formatted Input/Output by thopd (12.1k points)
ID: 26463 - Available when: Unlimited - Due to: Unlimited
| 17.4k views
3 like 0 dislike
86 answers
[Exercise] Coding (C) - asked Oct 5, 2017 in Chapter 4: Expressions by thopd (12.1k points)
ID: 25730 - Available when: Unlimited - Due to: Unlimited
| 15.7k views
12,783 questions
183,442 answers
172,219 comments
4,824 users