Day 2: Operators

                 Day 2: Operators

Day 2: operators in cpp, java, python
In this challenge, you'll work with arithmetic operators. Check out the Tutorial tab for learning materials and an instructional video!
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.
Note: Be sure to use precise values for your calculations, or you may end up with an incorrectly rounded result!
Input Format
There are 3 lines of numeric input:
The first line has a double,mealCost  (the cost of the meal before tax and tip).
The second line has an integer,tipPercent  (the percentage of mealCost being added as tip).
The third line has an integer,taxPercent  (the percentage of mealCost being added as tax).
Output Format
Print The total meal cost is totalCost dollars., where totalCost is the rounded integer result of the entire bill ( with mealCost added tax and tip).
Sample Input
Sample Output
The total meal cost is 15 dollars.


We round  to the nearest dollar (integer) and then print our result:
The total meal cost is 15 dollars.



#include <cmath>
#include <iostream>
using namespace std;
int main() {
    string tmp;
    getline(cin, tmp);
    double mealCost = stod(tmp);
    getline(cin, tmp);
    int tipPercent = stoi(tmp);
    getline(cin, tmp);
    int taxPercent = stoi(tmp);
    double tip = tipPercent * mealCost / 100;
    double tax = taxPercent * mealCost / 100;
    int totalCost = (int) round(tip + tax + mealCost);
    printf("The total meal cost is %i dollars.", totalCost);
    return 0;


import java.util.Scanner;
public class Solution {
    public static void main(String[] args) {
        Scanner scan = new Scanner(;
        double mealCost = scan.nextDouble(); // original meal price
        int tipPercent = scan.nextInt(); // tip percentage
        int taxPercent = scan.nextInt(); // tax percentage
        // Write your calculation code here.
        double tip = mealCost * tipPercent / 100;
        double tax = mealCost * taxPercent / 100;
        // cast the result of the rounding operation to an int and save it as totalCost
        int totalCost = (int) Math.round(mealCost + tip + tax);
        // Print your result
        System.out.println("The total meal cost is " + totalCost + " dollars.");


meal_cost = float(input())
tip_percent = int(input())
tax_percent = int(input())
tip = meal_cost * tip_percent / 100
tax = meal_cost * tax_percent / 100
total = meal_cost + tip + tax
print("The total meal cost is " + str(round(total)) + " dollars.")

Please do comment If u have any Queries!


Add a Comment

Your email address will not be published. Required fields are marked *