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
|
#include <iostream>
#include <iomanip>
using std::cout;
using std::cin;
using std::endl;
using std::setprecision;
using std::ios;
using std::setiosflags;
//function prototypes
void intro();
void selection(int &);
void getIncrease(double &);
void increasePrice(double, double[], int);
void displayPrices(double []);
void liner();
void quiter();
int main()
{
//declare variables
double rate = 0.0;
int s = 0;
//set decimal precision
cout << setiosflags(ios::fixed) << setprecision(2);
//declare array
double price[10] = {10.5, 25.5, 9.75, 6.0, 35.0, 100.4, 10.65, .56, 14.75, 4.78};
//processing/call functions
intro();
while(s >= 0 && s <= 9)
{
selection(s);
if(s >= 0 && s <= 9)
{
getIncrease(rate);
increasePrice(rate, price, s);
} //end if
}//end while
cout << endl;
liner();
displayPrices(price);
liner();
//pause before quitting
quiter();
return 0;
} //end of main function
//*****function definitions*****//
void intro()
{
cout << endl;
cout << " Ch11AppE05.cpp - updates prices of selected items" << endl;
cout << " Created/revised by <hankof1983> on <10/2/2008>" << endl << endl;
liner();
cout << " Enter item number you chose to modify." << endl;
cout << " >> When finished, enter '0'" << endl << endl;
liner();
} //end of intro function
void selection(int &s)
{
cout << " Enter item number: ";
cin >> s;
s = s - 1;
while(s > 9 || s < -1)
{
cout << endl << " ERROR: Please enter an item number 1-10," << endl;
cout << " or 0 to finish." << endl << endl;
cout << " Enter item number: ";
cin >> s;
s = s - 1;
} //end while
} //end of selection function
void getIncrease(double &r)
{
cout << " Enter price increase %";
cin >> r;
r = r * 0.01;
cout << endl;
} //end of getIncrease function
void increasePrice(double rate, double price[], int s)
{
price[s] = price[s] + (price[s] * rate);
rate = 0.0;
} //end of increasePrices function
void displayPrices(double price[])
{
cout << " NEW PRICES:" << endl << endl;
for (int x = 0; x < 10; x = x + 1)
cout << " Item " << x + 1 << ": $" << price[x] << endl;
//end for
cout << endl;
} //end of displayPrices function
void quiter()
{
cout << " Press ENTER to quit...";
cin.ignore(1);
cin.get();
} //end of quiter function
void liner()
{
cout << "-------------------------------------------------------------------------" << endl << endl;
} //end of liner function
|