1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
|
#include <iostream>
#include <conio.h>
#include <string>
using namespace std;
#include <windows.h> //required to implement screen coordinates
float books = 0;
const float hst = 0.13;
void gotoxy(int x, int y);
void clrscr(int x, int y);
float subTotal = 0.0;
void input();
void tax_calculator();
string again;
float isbn[5] = { 11110, 12221, 13332, 24443, 25554 };
string bookTitle[5] = {"Binary Kibbles and Bits", "Underwater Googles", "Vitamin C++", "Surf and Turf the Web", "Java-lin: Olympic Favourite" };
float retail[5] = { 155.95, 116.75, 126.50, 125.75, 138.99 };
int main()
{
do
{
clrscr(0,0);
gotoxy(8,1);
cout << "ISBN";
gotoxy(16,1);
cout << "Book";
gotoxy(44,1);
cout << "Price";
gotoxy(54,1);
cout << "Quantity";
gotoxy(66,1);
cout << "Total\n";
cout << "-------------------------------------------------------------------------------";
input();
}
while(again == "y");
}
void input()
{
restart:
char t = 'n';
string bookName;
int isbn_num;
int y = 3;
int quantity;
string letter;
for (int j = 0; j < 5; j++)
{
gotoxy(8,y);
cin >> isbn_num;
for(int i = 0; i < 5; i++)
{
if(isbn_num==isbn[i])
{
gotoxy(16,y);
cout << bookTitle[i];
gotoxy(44,y);
cout << "$" << retail[i];
gotoxy(54,y);
cin >> quantity;
float total = retail[i] * quantity;
gotoxy(66,y);
cout << "$" << total;
subTotal += total;
t = getch();
if(t == 't')
{
gotoxy(50,19);
cout << "Pre Tax Total: " << "$" << subTotal;
tax_calculator();
gotoxy(50, 22);
cout << "\n\n\tWould you like to restart? (y or n): ";
char answer;
cin >> answer;
if(answer == 'y')
{
goto restart;
}
else
{
cout << "Thank you and have a nice time"
system("PAUSE");
return 0;
}
}
y+=2;
}
}
}
cin.ignore();
}
void tax_calculator()
{
float tax = subTotal * hst;
float finalTotal = subTotal + tax;
gotoxy(50, 20);
cout << "Tax(HST): " << "$" << tax;
gotoxy(50,21);
cout << "After Tax Total: " << "$" << finalTotal;
}
//gotoxy function
void gotoxy(int x, int y)
{
COORD coord;
coord.X = x; //column coordinate
coord.Y = y; //row coordinate
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
}
//clrscr function
void clrscr(int x, int y)
{
COORD coordScreen = { x, y };
DWORD cCharsWritten;
CONSOLE_SCREEN_BUFFER_INFO csbi;
DWORD dwConSize;
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
GetConsoleScreenBufferInfo(hConsole, &csbi);
dwConSize = csbi.dwSize.X * csbi.dwSize.Y;
FillConsoleOutputCharacter(hConsole, TEXT(' '),
dwConSize, coordScreen, &cCharsWritten);
GetConsoleScreenBufferInfo(hConsole, &csbi);
FillConsoleOutputAttribute(hConsole, csbi.wAttributes,
dwConSize, coordScreen, &cCharsWritten);
SetConsoleCursorPosition(hConsole, coordScreen);
}
|