Previous Next
0 / 15
Module DEMO-33-63DEMO-OOP-33

Grocery Store Calculator

DEMO-OOP-33 โ€ข Object Oriented Programming

Browser-only practice

Problem Statement

Maria went to the grocery store and bought several items. She needs to calculate the total cost of her purchase including tax.

Write a program that reads the subtotal amount and tax rate, then calculates and displays the final total cost.

The formula is: Total = Subtotal + (Subtotal ร— Tax Rate)

For example, if the subtotal is $25.50 and the tax rate is 0.08 (8%), the total would be $25.50 + ($25.50 ร— 0.08) = $25.50 + $2.04 = $27.54.

Constraints

Subtotal amount is between 0.01 and 10000.00 Tax rate is between 0.00 and 0.50 (0% to 50%) All calculations should maintain precision and round only for the final output

Input Format

A single line containing two space-separated numbers:

  • The first number is the subtotal amount (float)
  • The second number is the tax rate as a decimal (float)

Example: 25.50 0.08

Output Format

A single line containing the total cost rounded to exactly 2 decimal places.

Example: 27.54

Sample Testcases

Submit runs every public testcase in this browser. Results and code never leave this device.

Sample #1
Public sample
25.50 0.08
27.54
Subtotal: $25.50, Tax: 8% โ†’ Tax amount: $2.04, Total: $27.54

Web terminal

C, C++, Java, and Python run locally in a browser VM. No worker or visualizer is used.

Saved in this browser
Editor settings