473,799 Members | 2,842 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Stuck on C++ program to calculate price and tax

63 New Member
I have to write a program that asks for a cost-per-item, number of items purchased, and a discount rate. Then it should calculate the total cost, tax due, and amount due.

I have to use the formulas:
total cost = number of items * cost-per-item
total cost (discounted) = total cost - (discount rate * total cost)
tax due = total cost * TAXRATE
amount due = total cost + tax due

I am going to put what I have so far. Any suggestions would be helpful. Also, how do I put the discount rate as a percentage?

Expand|Select|Wrap|Line Numbers
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include <iomanip>
  4. using namespace std;
  5.  
  6. int _tmain(int argc, _TCHAR* argv[])
  7. {
  8.     const float TAXRATE = 0.06f;
  9.     double costPerItem, itemsPurchased, discountRate, totalCost, taxDue, totalCostDiscounted;
  10.  
  11.     cout <<"\nEnter the cost-per-item: ";
  12.     cin >> costPerItem;
  13.     cout <<"\nEnter the number of items purchased: ";
  14.     cin >> itemsPurchased;
  15.     cout <<"\nEnter the discount rate: ";
  16.     cin >> discountRate;
  17.  
  18.     totalCost = itemsPurchased * costPerItem;
  19.     totalCostDiscounted = totalCost - (discountRate * totalCost);
  20.     taxDue = totalCost * TAXRATE;
  21.     cout << setiosflags (ios::fixed)
  22.          << setiosflags (ios::showpoint)
  23.          << setprecision(2);
  24.  
  25.     cout <<"\nThe total cost is: " << setw(4) << costPerItem*itemsPurchased  << endl;
  26.     cout <<"\nThe tax due is: " <<setw(4)<<costPerItem*itemsPurchased*TAXRATE << endl;
  27.     cout <<"\nThe amount due is: "<<setw(4)<<totalCost + taxDue<<endl;
  28.  
  29.     return 0;
  30. }
Sep 7 '07 #1
3 11805
Savage
1,764 Recognized Expert Top Contributor
I have to write a program that asks for a cost-per-item, number of items purchased, and a discount rate. Then it should calculate the total cost, tax due, and amount due.

I have to use the formulas:
total cost = number of items * cost-per-item
total cost (discounted) = total cost - (discount rate * total cost)
tax due = total cost * TAXRATE
amount due = total cost + tax due

I am going to put what I have so far. Any suggestions would be helpful. Also, how do I put the discount rate as a percentage?


#include "stdafx.h"
#include <iostream>
#include <iomanip>
using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
const float TAXRATE = 0.06f;
double costPerItem, itemsPurchased, discountRate, totalCost, taxDue, totalCostDiscou nted;

cout <<"\nEnter the cost-per-item: ";
cin >> costPerItem;
cout <<"\nEnter the number of items purchased: ";
cin >> itemsPurchased;
cout <<"\nEnter the discount rate: ";
cin >> discountRate;

totalCost = itemsPurchased * costPerItem;
totalCostDiscou nted = totalCost - (discountRate * totalCost);
taxDue = totalCost * TAXRATE;
cout << setiosflags (ios::fixed)
<< setiosflags (ios::showpoint )
<< setprecision(2) ;

cout <<"\nThe total cost is: " << setw(4) << costPerItem*ite msPurchased << endl;
cout <<"\nThe tax due is: " <<setw(4)<<cost PerItem*itemsPu rchased*TAXRATE << endl;
cout <<"\nThe amount due is: "<<setw(4)<<tot alCost + taxDue<<endl;

return 0;
}
Suggestions you say,hmm.How about couting totalCost and taxDue instead of:

Expand|Select|Wrap|Line Numbers
  1.     cout <<"\nThe total cost is: " << setw(4) << costPerItem*itemsPurchased  << endl;
  2.     cout <<"\nThe tax due is: " <<setw(4)<<costPerItem*itemsPurchased*TAXRATE << endl;
??

Also please use code tags for your code.

Oh,and one more question:

" Also, how do I put the discount rate as a percentage?"

Do you mean output it as percantage,inpu t it as percantage or both?

Savage
Sep 7 '07 #2
gator6688
63 New Member
I am not really sure what a code tag is? I also figured out the percent question. Thanks for the help.
Sep 11 '07 #3
Savage
1,764 Recognized Expert Top Contributor
I am not really sure what a code tag is? I also figured out the percent question. Thanks for the help.
You see # button in a message editor,well those arr code tags.

Savage
Sep 11 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

17
2038
by: JT | last post by:
Help me the following C++ question: Write a program to help a local bookshop automate its billing system. The program should do the following: (a)Let the user enter the ISBN, the system will trace the title and price of the book automatically. The system should check whether the book is in the stock or not. If it is not, please let the user to enter again. (b)Allow a customer to buy more than one item from the bookshop.
0
2426
by: georges the man | last post by:
The purpose: • Sorting and Searching • Numerical Analysis Design Specification You are to write a program called “StockAnalyser”. Your program will read a text file that contains historical price of a stock. The program will allow users to query the stock price of a particular date and output its statistics (mean price, median price and standard deviation) for any specified period. Your program must be menu driven and works as follows.
4
2763
by: georges the man | last post by:
hey guys, i ve been posting for the last week trying to understand some stuff about c and reading but unfortunaly i couldnt do this. i have to write the following code. this will be the last time i ask for an entire code or u can give me the outine of what to do and i ll do it by myself. the description is the following: the program will read a text file that contains historical price of a stock. The program will allow users to query...
109
25900
by: zaidalin79 | last post by:
I have a java class that goes for another week or so, and I am going to fail if I can't figure out this simple program. I can't get anything to compile to at least get a few points... Here are the assignments... 4. CheckPoint: Inventory Program Part 1 • Resource: Java: How to Program • Due Date: Day 5 forum • Choose a product that lends itself to an inventory (for example, products at your workplace, office supplies, music CDs, DVD...
2
3978
by: zaidalin79 | last post by:
Here is my Inventory program for my Java class.... //Inventory.java //Class created to store item information for Inventory purposes //Created November 15, 2006 //Modified November 29, 2006 //Audrey A. Paige //IT315 class Product
8
29131
by: Nasutperaah | last post by:
Hi all, I have written a C ++ program and now need to add a way to make it exit on command, or start over from the beginning. I have very little programming knowledge; Here is my code: Thanks in advance for any help. /////////////////////////////////////////////////////////////////////////////////////////////////// // ...
4
2313
nexcompac
by: nexcompac | last post by:
Ok, I posted a similar post but now need to jump back into it. Here is what I have been able to clean up. I am using textpad and jbuilder. Still getting used to the whole java world and I am trying to compile a program using TextPad. Here is what I have so far. /* * Main.java * * Created on July 19, 2007, 5:54 PM *
1
2521
by: Kayvine | last post by:
Hi guys, this is a question I have for an assignment, it is pretty long, but I am not asking for the code(well if someone wants to write I'll be really happy, lol), but I just want to know how to start it and what main topics in C I will need to cover in the assignment. Thanks a lot. CSC180 Assignment #3: Menu Madness Due Date: Thursday, November 8th at 1:00am Contents: · General Info · What to Hand In o Submission Instructions
1
2663
by: jcato77 | last post by:
I need help with a class project I'm working on, Below is my assignment and the code I have currently created. Assignment: Modify the Inventory Program by creating a subclass of the product class that uses one additional unique feature of the product you chose (for the DVDs subclass, you could use movie title, for example). In the subclass, create a method to calculate the value of the inventory of a product with the same name as the method...
0
9688
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9544
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10238
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10030
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6809
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5467
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5589
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3761
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2941
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.