1 like 1 dislike
13k 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

 

[Exam] asked in Midterm by (12.1k points)
ID: 32351 - Available when: 2017-11-15 14:10 - Due to: Unlimited
| 13k views

59 Answers

0 like 0 dislike
Hidden content!
#include<stdio.h>
#define FIXED_AMOUNT 10
int main()
{
* *** * * * ***** * * * * n;
* *** * * * * * * ** * * * *** ** ** ** * ***
***** * ** * * * ** * * ** ** * * * **** ***** *
** * ** ** * * * ** * *
** * * *** * ** *
* * *** ** *** * ** * *** ** *** * * = FIXED_AMOUNT + (n*0.6);
* * * *** *** * ** ** *** ***** * * ** * *** * * **** ****** ** **
* * ** ** ** * **
**** ** * ** * * * ** if(n<51)
    {
** * *** * ** * ** * ****** * * *** * * ** * = FIXED_AMOUNT + 30*(0.6) + (n-30)*0.8;
*** ***** **** ****** ** **** ******* *** ******** * **** * * * *** **** * **
    }
** ** ****** * * * * if(n<61)
** * *** * *** ** *
**** ** **** * ** ** * * ** *** * * *** * ** ** ** *** = FIXED_AMOUNT + 30*0.6 + 20*0.8 + (n-50)*1;
** * * ** * * * * ** ** ** ** *** * ***** * *** ** ** * * ***
** **** * * **** **
* *** * * **** * * ** * **
** *** *** *** * *
* * **** **** ** * *** ** * * **** **** * * * ** * = FIXED_AMOUNT + 30*0.6 + 20*0.8 + 10*1 + (n-60)*1.2;
* ***** * * ***** * * * * ** * * * * * ** **** * * *** * ** ** *
* * **** * ** * *
** * * ** * **** * ** *** * 0;
}
answered
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>
#define FIXED_AMOUNT 10
int main()
{
****** *** ** ** n;
*** * * * *** * ** * **** ** * * *** **
**** * * * * *** ***** * ** ** ** * ** ** *
* * * ** ** * ***** * * **
*** ** * ** *** ***
*** * * ** ** * * ** * ** * * * *** * ** = FIXED_AMOUNT + (n*0.6);
* ** * * ** ** ** * * ** * * **** ** ** ** ** * * * ** ***
* * ** * ***** **
*** ****** *** * * *** ** ***** if(n<51)
    {
** * ** * *** * * ** ** * ** **** ***** = FIXED_AMOUNT + 30*(0.6) + (n-30)*0.8;
** * *** *** * * *** **** ***** * * **** ** * ** * *** * * * *
    }
* * *** ** * ** ** * **** * if(n<61)
***** * **** * * * *** **
* * * ** * * ** * * *** *** * ** * **** ** * = FIXED_AMOUNT + 30*0.6 + 20*0.8 + (n-50)*1;
** ** * ******* * ***** * *** * * *** * * * * * * ** * *
*** ** * * ** *
** * ** ** * ** * ** *
* * * * ** ***** * *
* ** * * ** * **** * ** ** * * * * * ** * = FIXED_AMOUNT + 30*0.6 + 20*0.8 + 10*1 + (n-60)*1.2;
* **** * * *** *** * * * ** * * * *** *** * ** * *
** * **********
* **** * * * * ** * * * 0;
}
answered by (-281 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(){
* * * * **** * * **** v;
* ** ** ** * ** * ******* * *** * ** **
** ** ***** ** *** *** *** *
* *** * ****** * *** **** * *** * ** ** * * ** * * * ** %.2f",10+0.6*v );
* * * *** **
** * *** * ** * * *** * if(v<=50){
* * ****** ** * **** * ** *** *** ** ** * *** * * * %.2f",10+0.6*30 + 0.8*(v-30) );
** * * * * ** *
* ** * * ** **** ***** if(v<=60){
** * ** ****** **** ** * *** * * *** * ** %.2f",10+0.6*30 + 0.8*20 + 1*(v-50) );
** * * * * * * * ***
*** ** ***** * ****** **
*** * * **** ** * ***** *** ** * * ** * * *** **** * * + 0.8*20 + 1*10 + 1.2*(v-60) );
* * * ** * **** * *
* * * ** * ***** ** 0;
}
answered by (-116 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()

{
** *** * * * *** ****** * input,sum=0;
* ** ** ** * * ** * * ***** ** *** * * ** * * *

* ** ** * ** ** * (input<=30)
* *** * ** * ** * *
* ***** * * * * * ** ***** * **** * * ** * **
** ** * ***** * ****** * * *** * * * ** * * **** * %.2f",sum);
** *** * * *** **
** *** * * * * * * if (input<=50)
    {
* **** * ** * ** * ********* * **** * ** * *** * * * * *** **
** ** ** * * ***** * *** ******* * * *** * * ****** *** %.2f",sum);
** **** *** * * * ****
***** * ** * ** if (input<=60)
    {
*** *** ** ** ** *** * * * ** *** * * * * * ** ** **
* * **** *** ***** *** ** *** ***** * **** * ** * %.2f",sum);
* * * ** * ***** * * *
** * * * *** * ** * * if (input>60)
* *** ** * * ** *
** * * ** **** ****** * ** **** * * * * * ** ** *** **** * *
* * ****** * * **** * * ***** *** * * ** * ** %.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()
{
** * * * * * ** * * * *** x,y;

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

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

** *** ** ***** ** *** * if (x<=50)
** * ** **** * ******** * ** *** ** *** ** * *** * * * ** ****

********* ** * ***** ** * if (x<=60)
* * ** *** **** ** * *** * *** ********* * ** * ** *** **** * **

* * **** ** * * ** * y=10+30*0.6+20*0.8+10+(x-60)*1.2;

** **** * * ***** ** **** ** * * ** * %.2f",y);

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

}
answered by (-196 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>
#include <stdlib.h>

int main()
{
* * * ** ***** *** a;
** * * * * * *** **** * ** * * * * ** * *****
*** ** * *** *** **** * * ** * **** ** * * *
***** ** ** ** ** ** ** * *** *** * *** %.2f",10+a*0.6);
*** ** * * * * * ** **** **** * * * *** ** * * *
* *** **** **** ** * ** **** ***** ** *** *** * ***** %.2f",28+(a-30)*0.8);
* *** ** * ** * * * *** * * * * ** ** ** ** * * **
* ** * **** *** ** * ** ** ** *** ** ******** ** %.2f",44+(a-50)*1);
**** *** * *** ** **** *
* *** * ****** ** ** ****** * **** * * * *** * ***** ** * * *** * %.2f",54+(a-60)*1.2);
****** ** ** * * * * 0;
}
answered by (-498 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()
{
** *** ** * ** * * *** x,y;

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

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

** * * * * **** * * * * * * if (x<=50)
**** **** ** * **** * **** **** * * * * ** ** * * ** ***

* *** * ** * * ** if (x<=60)
* * ** * ******* **** ** **** ** **** ** * ** * ****

* * ** * ** * * **** * y=10+30*0.6+20*0.8+10+(x-60)*1.2;

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

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

}
answered by (-196 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() {
* ** ** * ** *** ** ** ** a;
* ** ** * ** * ** ** *** b;
** *** * * * * ** * **** * ** * &a);
*** ***** ***** *** * *** ** {
* ** *** ** * * * **** *** ** * * ** *** * **** ** *
* ** ** ***** * * **** *
* * * ***** * *** *** * if(a>30 && a<=50) {
* * ** * **** * * *** *** * * * * * *** **** * **
* *** ** * * *
*** * * ** *** *** ** * *** if(a>50 && a<=60) {
* * * * ** ** ** ** ** * *** * * * ** * ** ***
* ** * ** * ** *
** ** * *** * * * * *** if(a>60) {
*** ** *** * *** ** * *** * *** * *** *** * * **
* * ** ** **** * ***
** * **** * *** * ** * * * * ** %.2f", b);
}
answered by (-120 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>
#include <stdlib.h>

int main()
{
** * ** *** * * *** * a;
* * ** ** **** * * ** ** *** ** ** ** * ** ** * *
*** * * ****** *** * *** * * ** ** *** * * *
* * ** ** ***** **** * *** * *** * ** ** * ** *** %.2f",10+a*0.6);
*** * ** **** * * ***** *** ** **** ** * ** *
* **** ** * * * * * *** * * * * *** * ***** * ** ** * %.2f",28+(a-30)*0.8);
* * * ** *** *** * *** * * * ** * * * ** **
*** * * ** ** ** * **** * *** * * * * ** * ** ****** ** %.2f",44+(a-50)*1);
** * * * ** **** *
* * * ** **** * *** *** * ** * *** * *** * * %.2f",54+(a-60)*1.2);
* **** *** * * ** * * 0;
}
answered by (-498 points)
0 0
prog.c: In function 'main':
prog.c:13:26: warning: format '%f' expects argument of type 'double', but argument 2 has type 'int' [-Wformat=]
         printf("Cost: %.2f",44+(a-50)*1);
                          ^
Welcome to Peer-Interaction Programming Learning System (PIPLS) LTLab, National DongHwa University
English 中文 Tiếng Việt
IP:172.70.126.217
©2016-2025

Related questions

0 like 0 dislike
19 answers
[Exam] asked Dec 9, 2017 in Midterm by thopd (12.1k points)
ID: 36750 - Available when: 2017-11-15 14:10 - Due to: Unlimited
| 5.3k views
0 like 0 dislike
15 answers
[Exam] asked Dec 9, 2017 in Midterm by thopd (12.1k points)
ID: 36755 - Available when: 2017-11-15 14:10 - Due to: Unlimited
| 4.8k views
0 like 3 dislike
58 answers
[Exam] asked Nov 15, 2017 in Midterm by thopd (12.1k points)
ID: 32710 - Available when: 2017-11-15 14:10 - Due to: Unlimited
| 11.8k views
12,783 questions
183,442 answers
172,219 comments
4,824 users