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
|
#include "stdafx.h"
#include <iostream>
#include <string>
/****************************************/
// Namespace
/****************************************/
using namespace std;
int calculateNumCopies(int, char, char);
float calculateProfit(int, float);
void printResults(char*, float, float);
/*****************************************/
// Global constants
/*****************************************/
#define PAID_RATE 0.80
/********************************************************************************/
// main()
/********************************************************************************/
int main()
{
char isbn[10];
char RorS, NorO;
float price, profit, copies;
int i, enrollment;
int copy;
int count = 0;
do {
cout << "Enter book number ";
cin >> isbn;
cout << "Enter price per copy ";
cin >> price;
cout << "Enter expected class enrollment ";
cin >> enrollment;
cout << "Enter 'R' if required or 'S' is suggested ";
cin >> RorS;
cout << "Enter 'N' if required or 'O' is suggested ";
cin >> NorO;
copies = calculateNumCopies(enrollment, RorS, NorO);
profit = calculateProfit(copies, price);
cout << " The estimation for the next quarter is ";
printResults(isbn, copies, profit);
count++;
} while (count < 5);
system("pause");
return 0;
}
// print method to print the final results
void printResults(char* isbn, float copies, float profit)
{
cout << "\nISBN" << isbn;
cout << "\nCopies" << copies;
cout << "\nProfit" << profit;
}
// calculate the profits
float calculateProfit(int copies, float price)
{
float paidToStore = 0.0;
float totalAmount = 0.0;
totalAmount = copies * price;
// comment example
paidToStore = totalAmount * PAID_RATE;
return totalAmount - paidToStore;
}
//calculate the number of copies that are required
int calculateNumCopies(int intenrollment, char RorS, char Noro);
{
int copies = intenrollment;
if (RorS == 'R' || RorS == 'r')
{
if (NorO == 'N' || NorO == 'n')
copies = (int)copies * 0.90;
if (NorO == 'O' || NorO == 'o')
copies = (int)copies * 0.65;
}
if (RorS == 'S' || RorS == 's')
{
if (NorO == 'N' || NorO == 'n')
copies = (int)copies * 0.40;
if (NorO == 'O' || NorO == 'o')
copies = (int)copies * 0.20;
}
return copies;
}
|