0% found this document useful (0 votes)
1 views6 pages

Tanguin Double Machprobdsa

The document outlines a machine problem for a Data Structures and Algorithm course, focusing on creating a C++ program to calculate the total cost of purchased items with varying prices and quantities. It emphasizes the importance of accurate calculations, especially for fractional quantities, and provides a flowchart and sample code for implementation. The program allows users to input item prices and quantities, calculate costs, and display the total, making it a practical tool for both personal and business use.

Uploaded by

lancetanguin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views6 pages

Tanguin Double Machprobdsa

The document outlines a machine problem for a Data Structures and Algorithm course, focusing on creating a C++ program to calculate the total cost of purchased items with varying prices and quantities. It emphasizes the importance of accurate calculations, especially for fractional quantities, and provides a flowchart and sample code for implementation. The program allows users to input item prices and quantities, calculate costs, and display the total, making it a practical tool for both personal and business use.

Uploaded by

lancetanguin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Bicol University

Polangui

Data Structures and


Algorithm
Machine Problem:
(Double)

By: Lancelot R. Tanguin


Course & Block: BSCpE 2B
Professor: Melissa Jeankie Satiada-Rellon

Statement Problem
In today's modern world, shopping for groceries, goods, or even
online items often involves calculating the total cost of various
products with varying prices and quantities. Imagine you are
tasked with developing a simple yet effective tool to assist both
shopkeepers and customers in determining the total cost of their
purchases accurately and efficiently.
Consider a scenario where a small business owner or a shopper
needs to calculate the total amount spent on items with different
unit prices and quantities. For example, a customer may buy 3.5
kilograms of apples at $2.99 per kilogram or 2 liters of milk at
$1.25 per liter. Since these quantities are often fractional, they
require precise calculations to avoid errors that could lead to
overcharging or undercharging. This challenge becomes even
more critical in situations where multiple items are being
purchased, and the overall total needs to be calculated swiftly.
To solve this problem, design a program in C++ that allows users
to input the price of an item and the quantity purchased. The
program should then calculate the cost for each item and keep a
running total of all items added. Users should also have the
flexibility to add as many items as they wish. Once the user
decides to stop adding items, the program will display the total
cost of all purchases. This tool can serve as a helpful utility for
both personal use and small businesses looking to streamline
their checkout processes.
The program should ensure that the calculations are accurate,
especially for fractional quantities, by using the double data type
to handle decimal values. Additionally, the program should be
user-friendly, allowing users to decide whether to continue adding
items or stop when they are finished. By incorporating these
features, the program not only demonstrates the effective use of
the double data type but also provides a practical solution to a
common real-world problem.

Flowchart
CODE
#include <iostream>
#include <iomanip> // For formatting output
#include <string> // For handling user input (yes/no)
using namespace std;

int main() {
double price, quantity, totalCost = 0.0;
string choice;

cout << "Welcome to the Total Cost Calculator!\n";

do {
// Input price and quantity from the user
cout << "Enter the price of the item: ";
cin >> price;

cout << "Enter the quantity purchased: ";


cin >> quantity;
// Calculate the cost for the current item
double itemCost = price * quantity;
totalCost += itemCost; // Add to total cost

// Display the cost for the current item


cout << fixed << setprecision(2); // Format to 2 decimal
places
cout << "Cost for this item: $" << itemCost << endl;

// Ask if the user wants to add another item


cout << "Do you want to add another item? (yes/no): ";
cin >> choice;

} while (choice == "yes" || choice == "Yes");

// Display the total cost of all items


cout << "\nThe total cost of all items is: $" << totalCost <<
endl;
cout << "Thank you for using the calculator!\n";

return 0;
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy