Created
November 11, 2017 06:03
-
-
Save Ottzoa/38b2ba9b6fa589e60566c8a09c2b92b5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#unclude <iostream> | |
#include <string> | |
#include <iomanip> | |
using namespace std; | |
void print(string, string, double, double, int, int); | |
int main() | |
{ | |
string firstItem, secondItem; | |
double firstPrice, secondPrice; | |
int firstCount, secondCount; | |
//user input | |
cout << "What is the first item you are buying?" << endl; | |
getline(cin, firstItem); | |
cout << "What is the price of the " << firstItem << "?" << endl; | |
cin >> firstPrice; | |
cout << "How many " << firstItem << "s?" <<endl; | |
cin >> firstCount; | |
cin.ignore(); | |
cout << "What is the second item you are buying?" << endl; | |
getline(cin, secondItem); | |
cout << "what is the price of the " << secondItem << "?" << endl; | |
cin >> secondPrice; | |
cout << "How many " << secondItem << "s?" << endl; | |
cin >> secondCount; | |
print(firstItem, secondItem, firstPrice, secondPrice, firstCount, secondCount); | |
return 0; | |
} | |
void print(string firstItem, string secondItem, double firstPrice, double secondPrice, int firstCount, int secondCount) | |
{ | |
//math | |
double salesTax = 0.08675; | |
double firstExt = firstPrice * firstCount; | |
double secondExt = secondPrice * secondCount; | |
double subTotal = firstExt + secondExt; | |
double tax = subTotal * salesTax; | |
double total = tax + subTotal; | |
// receipt output | |
cout << setw(1) << "Item" << setw(20) << "Count" << setw(25) << "Price" << setw(30) << "Ext. Price" << endl; | |
cout << setw(1) << "====" << setw(20) << "=====" << setw(25) << "=====" << setw(30) << "==========" << endl; | |
cout << setw(1) << firstItem << setw(20) << firstCount<< setw(25) << setprecision (2) << fixed << firstPrice | |
<< setw(30) << setprecision (2) << fixed << firstExt<< endl; | |
cout << setw(1) << secondItem << setw(20) << secondCount<< setw(25) << setprecision (2) << fixed << secondPrice | |
<< setw(30) << setprecision (2) << fixed << secondExt << endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment