1 like 0 dislike
24k 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 | 24k views

91 Answers

0 like 0 dislike
Hidden content!
#include *** ***
int main(void)
{

int cm;
float cost;

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

if ** * *****
{
** ** * * * *** ** * * **** * **** *****
}

if **** * * ** *** * * * *
{

* ** *** * ** * *** * * * *** *
}

*** *** * * ** * * ** * ** * *
* * * *
** * **** *** ****** *** * * **** ******* *
 }


if (cm>0 *** ** ** ** * **
*** ** *** *** ** ***
* *** * * ** * * *** * * * ****** * *** ******
* * * * *
** ** * * * *** *** **** cost);



return 0;
}
answered by (-249 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 *** * *
{

int cm;
float cost;

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


if ******
* * * * ** * *
* * ** *** * *** cost);

else if *** ***
* ** ** ** *** * ** ** * *** * * * ***

else
** * * * ** ** ** * ** ** * * * **** * ****** ******* *

** * *** **** ** * * cost);

* ** ()


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

return 0;
}
answered by (-249 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 * **
{

int cm;
float cost;

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


if * *** **
*** ** ********* * * *
* * * *** ** ** cost);

else if * ** *
* ** * ** *** * * * **** ***** * * *

else
** * * * *** * * ********* * *** * **** ******

* ** ** * * * cost);

* ** * ()


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

return 0;
}
answered by (-249 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 * * * ** * *

int main (void)
{

*** * *** * * ** * fixed_charge=10;
* * ** ***** ** ***** y;



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

***** *** * * ** (y <= 30)
* ** *** ** *** *
** * ******* * *** * *** ** * ***** ** * * *** ** *
***** **** * *****
********** * ** * * * * (y>30 && y <=50)
***** * *** **** *** *


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


* * *** *** * ** * * ** * (y>50 && y <=60 )
******* * * * * * *
** *** * ****** ** ** *** * ** * ** ** * **** ****** ** * * * * ** *** ** * ***** fixed_charge);
**** *** * * *** *


** ** * ** ** * * * (y>60)
{
* * ** * * * **** * * *** *** ** * *** * * * * ** * *** * * *** **** ** fixed_charge);
** * ** *****




** ** ***** * ** * ** * 0;
}
answered by (-107 points)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
Case 4: Correct output
0 0
-----------Re-judge-----------
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 (void)
{

* ** ** ** * * * fixed_charge=10;
*** * ** ** * * ** *** y;
* ** *** x;


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

* * * *** ** (y <= 30)
* **** * ****
**** * * * * *** ** * * * *** ** **** * * ** * **** *** ** ***
* * * * *
* ** **** **** * ** **** (y>30 && y <=50)
******* * *** ** * **** *


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


* * ***** *** ** **** * *** (y>50 && y <=60 )
** **** * * ****** *** *
* * * *** * * * ** * ** * * * ***** * *** * ****** ** ** ** * *** * ** fixed_charge);
** ** ****** * ** ***


* * *** ** **** (y>60)
{
* *** **** * *** * * * ******* * **** * ** *** * ** * * ** fixed_charge);
* * ** * **




*** ** ** * * * ** **** 0;
}
answered by (-107 points)
0 0
prog.c: In function 'main':
prog.c:8:8: error: unused variable 'x' [-Werror=unused-variable]
    int x;
        ^
cc1: all warnings being treated as errors
0 like 0 dislike
Hidden content!
#include * * *****
int main()
{
** * * * * * ****** * ** * * ** * * ** *
** *** ** ** * * * * ** * * * * * * ** ** * ***
* **** ** * * *** ** (a<=30)
* ********* * ** ** * ****** = 0.6*a +10;
** *** ** ** * * **** * * **** %.2f",cost1);
* ** *** * ** * * *** *
** *** * ** ***** * ***** if (a<=50)
***** ** ** ** ***** = 30*0.6 + 0.8*(a-30) +10;
* *** *** * * * ** ** * ** * * ** * * *
** * * * * * * if (a<=60)
** *** * **** ** *
* ** * * **** * * * ********** ** ** * * * = 30*0.6 + 0.8*(20) + 1*(a-50) +10;
** * * * ** ********* ** * ** ** ****** ** ** * ** ** %.2f",cost3);
* ** * * * **** * * **
* ****** ** * *** **** if (a>60)
** ** * *** * * *
* *** * * * ***** *** * **** ** * * * = 30*0.6 + 0.8*20+ 10 + 1.2*(a-60) +10;
* * * * * * * * * * ** * *** ** * *** ** %.2f",cost4);
** * *** * * *** *

* * * * * ** ** ***** 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 0
-----------Re-judge-----------
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!
** * * **** * **
****** main ()
{
** a,b;
* ** ** *** * ***
if * * * * *
* * * ** * * * *** ***
else if * *** **

* * * * + ** **
else if **
*** * * * *
else *** * * * * * *
*** ** * *** ** * ***

** 0 ;
}
answered by (-254 points)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
Case 4: Correct output
0 0
-----------Re-judge-----------
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 (void)
{
* * * * * * * * ** **** * a;
**** * ** * * *** * cost;
* ** *** * ** ** **** * * * ** *** * ** * * ** *****
* * *** ** *** ** *** *** (a>60)
* * **** *** ** ** *
* *** **** * ** * ** * * ** ***** ******* * * * * *** ** * * *
* *** * *** ** ** * * * *
** * ** *** * * ** * * ***** * (a>50 && a<=60)
** * ** ** *** * ** * * *
* *** * * ** * * * * * ** ** * ** * ** ** * **** ***** ** * *** *
* ** ** * * * * *
* ****** ****** * * (a>30 && a<=50)
** * * * *** ***** ** * *
*** *** * ** * * ***** * ** * **** *** * * * * ((a-30)*0.8)+(30*0.6)+10;
* * * * * *** *** ***
* ** * *** * * ** *** ** *** (a>0 && a<=30)
* ** ** * ** * ** * **
*** ** * * * * **** * * * * ** * * **** *** ** ** ** *** *
* **** * * **** * * * **
**** *** ** *** *** ** * * * ** * * %.2f",cost);
* * * * **** * ** * * ** * *** 0;
}
answered by (-168 points)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
Case 4: Correct output
0 0
-----------Re-judge-----------
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 (void)
{
** * ***** *** ** * a;
* ** * * * ** * * * * * cost;
* * ** * * ** ** * * * ** * ** ***
* * * * * ** * * * * (a>60)
* *** ** * * **** * *
* ** * * * * ** * * ** * * *** ** * * * * *** * *** *** * * **** * ** *
    }
* * * * ** * * *** ********** * (a>50 && a<=60)
*** ** * * * ***** ** ** * *
* * * * *** * *** ** ** ** **** * ** *** * *** * * ** * ** * *** * * ***
* * * ****** * ** *** *
* * * * * ** * ** ** * * * * (a>30 && a<=50)
* ** ** * **** * * ***
*** * ** * ** * *** ***** * * ***** *** * * * ((a-30)*0.8)+(30*0.6)+10;
* ** *** ** *** ** ** *
* * ** * * ***** ** * * (a>0 && a<=30)
* * * * ** * *** * *** * **
* ** * * ** * ** * ** * ** *** ** * ** * * **
*** **** ** *** *** * * * **
** * ** ***** ** * * ***** * * ** ** ***
* **** **** * * * ** * ** 0;
}
answered by (-168 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 ********* ** * **
int main(void)
{

int a;
float b , c, d, e;

** ** ** ** * * * *** &a);
if *****
{
* ***** ** ** * ***** * ** ***
* * * *** * * * ** *** ** * **** * b);
}
* * * * if (a>30 *** * * * ** ** *
{
* * ** * * * * * * * *** * *
* ** * * *** * ** * * * * *** ** c);
}
else if * * *** ** ** * ****
{
* ** ** ** ** ** * ** * *** ** * * *
* *** * * ******* ** ** * * * *** d);

}
else
{
** * ** *** **** * ** * ** ** *
**** * * * * ** *** * * * e);

}
** ** * ****** * 0;
* ** ** *** ***
answered by (-304 points)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
Case 4: Correct output
0 0
-----------Re-judge-----------
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
Case 4: Correct output
Welcome to Peer-Interaction Programming Learning System (PIPLS) LTLab, National DongHwa University
English 中文 Tiếng Việt
IP:104.23.197.64
©2016-2026

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
| 19k 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
| 17.4k views
12,783 questions
183,442 answers
172,219 comments
4,824 users