Skip to content

Commit c255478

Browse files
authored
Create Day2-Operators.c
The entire function has not been written, only the code for the empty portion is included.
1 parent 2c6f4cb commit c255478

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/* Task
2+
Given the meal price (base cost of a meal), tip percent (the percentage of the meal price being added as tip), and tax percent (the percentage of the meal price being added as tax) for a meal, find and print the meal's total cost. Round the result to the nearest integer.
3+
4+
Example
5+
6+
7+
8+
A tip of 15% * 100 = 15, and the taxes are 8% * 100 = 8. Print the value and return from the function.
9+
10+
Function Description
11+
Complete the solve function in the editor below.
12+
13+
solve has the following parameters:
14+
15+
int meal_cost: the cost of food before tip and tax
16+
int tip_percent: the tip percentage
17+
int tax_percent: the tax percentage
18+
Returns The function returns nothing. Print the calculated value, rounded to the nearest integer.
19+
20+
Note: Be sure to use precise values for your calculations, or you may end up with an incorrectly rounded result.
21+
22+
Sample Input
23+
24+
12.00
25+
20
26+
8
27+
Sample Output
28+
29+
15 */
30+
31+
#include <assert.h>
32+
#include <limits.h>
33+
#include <math.h>
34+
#include <stdbool.h>
35+
#include <stddef.h>
36+
#include <stdint.h>
37+
#include <stdio.h>
38+
#include <stdlib.h>
39+
#include <string.h>
40+
41+
char* readline();
42+
43+
// Complete the solve function below.
44+
void solve(double meal_cost, int tip_percent, int tax_percent) {
45+
double tip = meal_cost * tip_percent / 100;
46+
double tax = meal_cost * tax_percent / 100;
47+
int total =(int)round(meal_cost + tip + tax);
48+
printf("%d",total);
49+
}
50+
int main()
51+
{
52+
double mo;
53+
int tp,tp1;
54+
scanf("%lf",&mo);
55+
scanf("%d",&tp);
56+
scanf("%d",&tp1);
57+
solve(mo,tp,tp1);
58+
}

0 commit comments

Comments
 (0)