// DataEntry3.cpp : Defines the entry point for the console application. /* _________________________________________ D A T A E N T R Y P A R T 3 Working with currency Native Code Version This project teaches you how to use simple math computations to compute sales tax and how to format the results to look like currency. NOTE: cin only reads chars up to a white space so if you need to read a line with spaces, use getline() function. I did this to get the name of the item they purchased in line 48. Run without debugging (CTL - F5) _________________________________________ */ //---add the usual suspects! #include "stdafx.h" #include #include using namespace std; int main() { //---define our variables here string myTitle = " Welcome to Ron's Golf Store and Simple Calculations\n\n"; string whichProduct; double price = 0; double taxRate = .08; double salesTax = 0; double balanceDue = 0; // << is called an insertion operator. >> is called a extraction operator cout << myTitle << "\n\n"; //a welcome prompt //STEP 1: INPUT cout << "Enter name of item you wish to purchase: "; //prompt them for item getline(cin,whichProduct); //read the entire line including spaces cout << "Enter price of the item: "; //Prompt for price cin >> price; //get it cin.ignore (); //STEP 2: PROCESS THE DATA salesTax = price * taxRate; //compute tax balanceDue = price + salesTax; //total due //STEP 3: NOW DISPLAY THE OUTPUT //---format numbers cout.precision (2); //set format to 2 decimals cout << "\n\nSummary of Purchase" << "\n\n"; cout << "You purchased: " << whichProduct << endl; cout << "The price of your item is " << fixed << price << endl; cout << "Your sales tax is " << fixed << salesTax << "\n\n"; cout << "\n\nYour total purchase is $" << fixed << balanceDue << endl; return 0; }