Skip to content

Instantly share code, notes, and snippets.

@arafin1
Created July 13, 2020 17:38
Show Gist options
  • Save arafin1/71c61df7e89928720aa064447fca8a9c to your computer and use it in GitHub Desktop.
Save arafin1/71c61df7e89928720aa064447fca8a9c to your computer and use it in GitHub Desktop.
#include<iostream>
#include <math.h>
#include <vector>
using namespace std;
int StartUp(){
int bookCode;
cout << "Please enter the book code: ";
cin>>bookCode;
return bookCode;
}
int singleCopyPrice(){
int price;
cout <<"single copy price: ";
cin>> price;
return price;
}
int numberOnHand(){
int number;
cout <<"number on hand: ";
cin>>number;
return number;
}
int prospectiveStudent(){
int number;
cout <<"prospective enrollment: ";
cin>>number;
return number;
}
int requiredOroptional(){
int option;
cout <<"1 for reqd/0 for optional: ";
cin>>option;
return option;
}
int NewOrUsed(){
int option;
cout <<"1 for new/0 for used: ";
cin>>option;
return option;
}
int inventoryResult(int inventory, int enroll, int number, int reqOrop){
if(reqOrop == 1){
inventory = enroll * 0.40;
inventory = abs(inventory - number);
return inventory;
}
if(reqOrop == 0){
inventory = enroll * 0.20;
inventory = abs(inventory - number);
return inventory;
}
}
int numberOfBookToBuy(int inventory,int enroll, int number,int newOruse){
if(newOruse == 1){
inventory = enroll * 0.9;
inventory = abs(inventory - number);
return inventory;
}
if(newOruse == 0){
inventory = enroll * 0.65;
inventory = abs(inventory - number);
return inventory;
}
}
int summerizeInput(){
int bookCode = StartUp();
int price = singleCopyPrice();
int enroll = prospectiveStudent();
int number = numberOnHand();
int inventory = number;
int n = requiredOroptional();
int n2 = NewOrUsed();
int inventoryReq = inventoryResult( inventory,enroll,number,n);
int numberofBook = numberOfBookToBuy(inventoryReq, enroll,number,n2);//numbook - invve
cout<<"***************************************************"<<endl;
cout<<"Book: "<<bookCode<<endl;
cout<<"Price: "<<price<<endl;
cout<<"Inventory: "<<inventoryReq<<endl;
cout<<"Enrollment: "<<enroll<<endl;
cout<<endl;
if((n == 0) && (n2 == 0)){
cout<< "This book is optional and used."<<endl;
}
if((n == 0) && (n2 == 1)){
cout<< "This book is optional and New."<<endl;
}
if((n == 1) && (n2 == 0)){
cout<< "This book is required and used."<<endl;
}
if((n == 1) && (n2 == 1)){
cout<< "This book is required and New."<<endl;
}
int cost = numberofBook * price;
cout<<"***************************************************"<<endl;
cout<<"Need to order: "<< numberofBook<<endl;
cout<<"Total Cost: "<< cost<<endl;
cout<<"***************************************************"<<endl;
return cost;
}
vector<int> result;
void totalCost(int cost){
result.push_back(cost);
}
int main(){
int cost = 0;
int totalCo= 0;
char done;
do {
cost = summerizeInput();
totalCost(cost);
cout<<"Enter y to do another book,n to stop."<<endl;
cin>>done;
} while (done != 'n');
for(auto res : result){
totalCo +=res;
}
cout<<"***************************************************"<<endl;
cout<<"Total for all orders: "<< totalCo<<endl;
cout<<"Profit: "<< (totalCo - (totalCo * 0.8))<<endl;
cout<<"***************************************************"<<endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment