SlideShare a Scribd company logo
C programming tweak needed for a specific program.
This is the complete program up and running. except for one modification that my teacher is
requiring but it is confusing me.
The program needs to allocate disjoint memory and use that.
right now im allocating a continous block of memory on the heap but I need it to do disjoing
memory instead.
// Purpose: Program will allow a reseller to save their sales and calculate their profits.
// Also able to view highest profitable items and remove any sales they no longer want in their
sales inventory.
#define _CRT_SECURE_NO_WARNINGS
#include
#include
#include
#define PAUSE system("pause")
#define CLS system("cls");
//#define FLUSH fflush(stdin);
//////////////// SRUCTS BELOW //////////////////////////
typedef struct
{
char itemName[40];
float purchasePrice;
float soldPrice;
float shippingPrice;
float ebayFee;
float payPalFee;
float profit;
}SALES;
////////// FUNCTION PROTOTYPE BELOW /////////////
void addSale(SALES *Inventory, int *InventoryCounter);
void displayMenu(int *InventoryCounter);
void displayProfit(int *InventoryCounter, SALES *Inventory);
void displaySales(int *InventoryCounter, SALES *Inventory);
int getChoice(int *InventoryCounter);
void searchSale(SALES* Inventory, int InventoryCounter);
void sortProfits(SALES* Inventory, int InventoryCounter);
void removeSale(SALES* Inventory, int *InventoryCounter);
main() {
int SIZE;
int userChoice;
int InventoryCounter = 0;
//printf("********************* ");
//printf("* Welcome Reseller! * ");
//printf("********************* ");
printf("Enter the size of todays inventory:");
scanf("%i", &SIZE);
SALES *Inventory;
Inventory = calloc(SIZE, sizeof(SALES));//Using dynamic memory to allocate space on the
heap
do {
userChoice = getChoice(&InventoryCounter);
switch (userChoice) {
case 1:// Add a Sale
if (InventoryCounter == SIZE) // statement checks so we dont exceed the size of the
inventory user wants to enter.
{
printf("You Have Reached Max Inventory  ");
PAUSE;
}
else {
addSale(&(Inventory[InventoryCounter]), &InventoryCounter);
}
break;
case 2: // Display all sales records
displaySales(&InventoryCounter, Inventory);
PAUSE;
break;
case 3: // Display all profits
sortProfits(Inventory, InventoryCounter);
displayProfit(&InventoryCounter, Inventory);
PAUSE;
break;
case 4: // Display Inventory
searchSale(Inventory, InventoryCounter);
break;
case 5:// remove a sale
removeSale(Inventory, &InventoryCounter);
break;
case 6: // Quit
break;
default:
printf("Please choose a valid option ");
PAUSE;
break;
}// end of switch
} while (userChoice != 6);
free(Inventory);
} // End of main
//////////////////////////////////////////// FUNCTIONS BELOW //////////////////////////////////////////////////
void addSale(SALES *Inventory, int *InventoryCounter)// Function that adds sale and
calculates the fees in the background.
{
float payPalFee = 0; // variable to store the paypal fee from 1 sale
float ebayFee = 0; // variable to store ebay fee for 1 sale
/////////////// GETTING INVENTORY DETAILS ////////////////
printf("Enter the Item name: ");
scanf(" %[A-Z a-z]", Inventory->itemName);
printf(" Enter the item's purchase price: ");
scanf(" %f", &(Inventory->purchasePrice));
printf(" Enter the items Sold Price : ");
scanf(" %f", &(Inventory->soldPrice));
printf(" Enter the item Shipping Price: ");
scanf(" %f", &(Inventory->shippingPrice));
///////////////////////////////////////////////////////////
/////////////// Fees Calculated below ////////////////
payPalFee = (Inventory->soldPrice) * (.03) + .30; // Calculating Paypals fee Which is 3% of
sold price plus .30 cents
ebayFee = (Inventory->soldPrice)* (.10); // Caluculating Ebays fee which is 10% of sold
price
Inventory->payPalFee = payPalFee; // Saving the paypal fee for this specific item in struct
Inventory->ebayFee = ebayFee; // Saving the ebay fee for this specific item in struct
// calculating the profit for this 1 secific item based on details provided (line below) //
Inventory->profit = Inventory->soldPrice - Inventory->payPalFee - Inventory->ebayFee -
Inventory->purchasePrice - Inventory->shippingPrice;
(*InventoryCounter)++; // Incrementing Inventory counter ( amount of sales)
} // End of addSale
void searchSale(SALES* Inventory, int InventoryCounter) // function that searches for a sale by
name
{
char name[100]; // array to hold item searched name
char found = 'N'; // Flag variable
int i; // loop control variable
////// Ask User for item name //////
printf("What item are you searching for? ");
scanf("%s", name);
for (i = 0; i < InventoryCounter; i++)
{
if (strcmp(name, Inventory[i].itemName) == 0)// returns 0 if item was found, then we can
display the item details.
{
printf(" |Name|t|Purchase Price|t|soldPrice|t|Profit| ");
printf(" %.6s ttt$%.2f tt$%.2f tt$%.2f ", Inventory[i].itemName,
Inventory[i].purchasePrice, Inventory[i].soldPrice, Inventory[i].profit);
found = 'Y';//flag changed to illustrate item was found
PAUSE;
}// end if statment
}// end for loop
if (found == 'N') // if strcmp does not return 0 and flag stays 'N' then item will not be in
inventory
{
printf("Item not found ");
PAUSE;
}
}// end search Sales function
void displayProfit(int *InventoryCounter, SALES *Inventory) // Function that displays the
profit details of each item.
{
int i; // loop control variable
CLS;
printf("|Name|t| Profit| ");
for (i = 0; i < *InventoryCounter; i++)// loops through all the items and displays their name
and profit detials.
{
printf("%st%.2f ", Inventory[i].itemName, Inventory[i].profit);
} // End of for loop
} // End of displayProfit
void displayMenu(int *InventoryCounter) // Fucntion that displays the Main Menu
{
CLS;
printf("******** Main Menu ********* ");
printf("1. Add a sale. ");
printf("2. Display all Inventory records. ");
printf("3. Display all Inventory profits (high to low). ");
printf("4. Search inventory for a specific item . ");
printf("5. Remove a Sale from Inventory  ");
printf("6. Quit. ");
printf("Current Sales: %i ", *InventoryCounter);
printf("Enter your choice: ");
} // End of displayMenu
void displaySales(int *InventoryCounter, SALES *Inventory) // Fucntion that Displays all sales
records
{
int i; // loop control variable
CLS;
printf(" |Name|tt|Purchase Price|t|soldPrice|tt|shippingPrice| ");
for (i = 0; i < *InventoryCounter; i++) // loops through all the inventory and displays details
{
printf(" %.6s ttt$%.2f ttt$%.2f ttt $%.2f ", Inventory[i].itemName,
Inventory[i].purchasePrice, Inventory[i].soldPrice, Inventory[i].shippingPrice);
} // End of for loop
} // End of displaySales
int getChoice(int *InventoryCounter)// Function that returns the user Choice from menu
{
int result;
displayMenu(InventoryCounter);
while (getchar() != ' ') {};
scanf(" %i", &result);
return result;
} // End of getChoice
void sortProfits(SALES *Inventory, int InventoryCounter)// Function that sorts all the profits
from highest to lowest
{
int i, j;// loop control variable
SALES temp;// temp place holder.
for (i = 0; i < (InventoryCounter - 1); i++)
{
for (j = 0; j < InventoryCounter - i - 1; j++)
{
if (Inventory[j].profit < Inventory[j + 1].profit)
{
temp = Inventory[j];
Inventory[j] = Inventory[j + 1];
Inventory[j + 1] = temp;
}
}
}// end for loop through all inventory
}// End Sort Profits function
void removeSale(SALES* Inventory, int *InventoryCounter) {
char name[100];// char array to hold item searched name
int i, j; // loop control variable
char found = 'N';// Flag variable
printf("What item do you want to remove? ");
scanf("%s", name);
for (i = 0; i < *InventoryCounter; i++)
{
if (strcmp(name, Inventory[i].itemName) == 0) //if strcmp returns 0 then item will be
removed from inventory
{
for (j = i; j < *InventoryCounter - 1; j++)
Inventory[j] = Inventory[j + 1];
(*InventoryCounter)--;
printf(" Item Succesfully Removed ");
found = 'Y';
PAUSE;
}// end if statement
}// end for loop
if (found == 'N') // if strcmp does not return 0 and flag stays 'N' then item will not be in
inventory
{
printf("Item not found ");
PAUSE;
}// end else statement
}// end removeSale function
Solution
#define _CRT_SECURE_NO_WARNINGS
#include
#include
#include
#define PAUSE system("pause")
#define CLS system("cls");
//#define FLUSH fflush(stdin);
//////////////// SRUCTS BELOW //////////////////////////
typedef struct SALESINFO
{
char itemName[40];
float purchasePrice;
float soldPrice;
float shippingPrice;
float ebayFee;
float payPalFee;
float profit;
}SALES;
////////// FUNCTION PROTOTYPE BELOW /////////////
void addSale(SALES *Inventory, int *InventoryCounter);
void displayMenu(int *InventoryCounter);
void displayProfit(int *InventoryCounter, SALES *Inventory);
void displaySales(int *InventoryCounter, SALES *Inventory);
int getChoice(int *InventoryCounter);
void searchSale(SALES* Inventory, int InventoryCounter);
void sortProfits(SALES* Inventory, int InventoryCounter);
void removeSale(SALES* Inventory, int *InventoryCounter);
main() {
int SIZE;
int userChoice;
int InventoryCounter = 0;
//printf("********************* ");
//printf("* Welcome Reseller! * ");
//printf("********************* ");
printf("Enter the size of todays inventory:");
scanf("%i", &SIZE);
//SALES *Inventory;
struct SALESINFO *Inventory;
Inventory=(struct SALESINFO *) malloc (SIZE * sizeof(struct SALESINFO));
//Inventory = calloc(SIZE, sizeof(SALES));//Using dynamic memory to allocate space on the
heap
do {
userChoice = getChoice(&InventoryCounter);
switch (userChoice) {
case 1:// Add a Sale
if (InventoryCounter == SIZE) // statement checks so we dont exceed the size of the inventory
user wants to enter.
{
printf("You Have Reached Max Inventory  ");
PAUSE;
}
else {
addSale(&(Inventory[InventoryCounter]), &InventoryCounter);
}
break;
case 2: // Display all sales records
displaySales(&InventoryCounter, Inventory);
PAUSE;
break;
case 3: // Display all profits
sortProfits(Inventory, InventoryCounter);
displayProfit(&InventoryCounter, Inventory);
PAUSE;
break;
case 4: // Display Inventory
searchSale(Inventory, InventoryCounter);
break;
case 5:// remove a sale
removeSale(Inventory, &InventoryCounter);
break;
case 6: // Quit
break;
default:
printf("Please choose a valid option ");
PAUSE;
break;
}// end of switch
} while (userChoice != 6);
free(Inventory);
} // End of main
//////////////////////////////////////////// FUNCTIONS BELOW //////////////////////////////////////////////////
void addSale(SALES *Inventory, int *InventoryCounter)// Function that adds sale and calculates
the fees in the background.
{
float payPalFee = 0; // variable to store the paypal fee from 1 sale
float ebayFee = 0; // variable to store ebay fee for 1 sale
/////////////// GETTING INVENTORY DETAILS ////////////////
printf("Enter the Item name: ");
scanf(" %[A-Z a-z]", Inventory->itemName);
printf(" Enter the item's purchase price: ");
scanf(" %f", &(Inventory->purchasePrice));
printf(" Enter the items Sold Price : ");
scanf(" %f", &(Inventory->soldPrice));
printf(" Enter the item Shipping Price: ");
scanf(" %f", &(Inventory->shippingPrice));
///////////////////////////////////////////////////////////
/////////////// Fees Calculated below ////////////////
payPalFee = (Inventory->soldPrice) * (.03) + .30; // Calculating Paypals fee Which is 3% of
sold price plus .30 cents
ebayFee = (Inventory->soldPrice)* (.10); // Caluculating Ebays fee which is 10% of sold price
Inventory->payPalFee = payPalFee; // Saving the paypal fee for this specific item in struct
Inventory->ebayFee = ebayFee; // Saving the ebay fee for this specific item in struct
// calculating the profit for this 1 secific item based on details provided (line below) //
Inventory->profit = Inventory->soldPrice - Inventory->payPalFee - Inventory->ebayFee -
Inventory->purchasePrice - Inventory->shippingPrice;
(*InventoryCounter)++; // Incrementing Inventory counter ( amount of sales)
} // End of addSale
void searchSale(SALES* Inventory, int InventoryCounter) // function that searches for a sale by
name
{
char name[100]; // array to hold item searched name
char found = 'N'; // Flag variable
int i; // loop control variable
////// Ask User for item name //////
printf("What item are you searching for? ");
scanf("%s", name);
for (i = 0; i < InventoryCounter; i++)
{
if (strcmp(name, Inventory[i].itemName) == 0)// returns 0 if item was found, then we can
display the item details.
{
printf(" |Name|t|Purchase Price|t|soldPrice|t|Profit| ");
printf(" %.6s ttt$%.2f tt$%.2f tt$%.2f ", Inventory[i].itemName,
Inventory[i].purchasePrice, Inventory[i].soldPrice, Inventory[i].profit);
found = 'Y';//flag changed to illustrate item was found
PAUSE;
}// end if statment
}// end for loop
if (found == 'N') // if strcmp does not return 0 and flag stays 'N' then item will not be in
inventory
{
printf("Item not found ");
PAUSE;
}
}// end search Sales function
void displayProfit(int *InventoryCounter, SALES *Inventory) // Function that displays the profit
details of each item.
{
int i; // loop control variable
CLS;
printf("|Name|t| Profit| ");
for (i = 0; i < *InventoryCounter; i++)// loops through all the items and displays their name and
profit detials.
{
printf("%st%.2f ", Inventory[i].itemName, Inventory[i].profit);
} // End of for loop
} // End of displayProfit
void displayMenu(int *InventoryCounter) // Fucntion that displays the Main Menu
{
CLS;
printf("******** Main Menu ********* ");
printf("1. Add a sale. ");
printf("2. Display all Inventory records. ");
printf("3. Display all Inventory profits (high to low). ");
printf("4. Search inventory for a specific item . ");
printf("5. Remove a Sale from Inventory  ");
printf("6. Quit. ");
printf("Current Sales: %i ", *InventoryCounter);
printf("Enter your choice: ");
} // End of displayMenu
void displaySales(int *InventoryCounter, SALES *Inventory) // Fucntion that Displays all sales
records
{
int i; // loop control variable
CLS;
printf(" |Name|tt|Purchase Price|t|soldPrice|tt|shippingPrice| ");
for (i = 0; i < *InventoryCounter; i++) // loops through all the inventory and displays details
{
printf(" %.6s ttt$%.2f ttt$%.2f ttt $%.2f ", Inventory[i].itemName,
Inventory[i].purchasePrice, Inventory[i].soldPrice, Inventory[i].shippingPrice);
} // End of for loop
} // End of displaySales
int getChoice(int *InventoryCounter)// Function that returns the user Choice from menu
{
int result;
displayMenu(InventoryCounter);
while (getchar() != ' ') {};
scanf(" %i", &result);
return result;
} // End of getChoice
void sortProfits(SALES *Inventory, int InventoryCounter)// Function that sorts all the profits
from highest to lowest
{
int i, j;// loop control variable
SALES temp;// temp place holder.
for (i = 0; i < (InventoryCounter - 1); i++)
{
for (j = 0; j < InventoryCounter - i - 1; j++)
{
if (Inventory[j].profit < Inventory[j + 1].profit)
{
temp = Inventory[j];
Inventory[j] = Inventory[j + 1];
Inventory[j + 1] = temp;
}
}
}// end for loop through all inventory
}// End Sort Profits function
void removeSale(SALES* Inventory, int *InventoryCounter) {
char name[100];// char array to hold item searched name
int i, j; // loop control variable
char found = 'N';// Flag variable
printf("What item do you want to remove? ");
scanf("%s", name);
for (i = 0; i < *InventoryCounter; i++)
{
if (strcmp(name, Inventory[i].itemName) == 0) //if strcmp returns 0 then item will be removed
from inventory
{
for (j = i; j < *InventoryCounter - 1; j++)
Inventory[j] = Inventory[j + 1];
(*InventoryCounter)--;
printf(" Item Succesfully Removed ");
found = 'Y';
PAUSE;
}// end if statement
}// end for loop
if (found == 'N') // if strcmp does not return 0 and flag stays 'N' then item will not be in
inventory
{
printf("Item not found ");
PAUSE;
}// end else statement
}// end removeSale function
-------------------------
output sample:-
******** Main Menu *********
1. Add a sale.
2. Display all Inventory records.
3. Display all Inventory profits (high to low).
4. Search inventory for a specific item .
5. Remove a Sale from Inventory
6. Quit.
Current Sales: 0
Enter your choice: 1
Enter the Item name: XYZ
Enter the item's purchase price: 4
Enter the items Sold Price : 6
Enter the item Shipping Price:2
******** Main Menu *********
1. Add a sale.
2. Display all Inventory records.
3. Display all Inventory profits (high to low).
4. Search inventory for a specific item .
5. Remove a Sale from Inventory
6. Quit.
Current Sales: 1
Enter your choice: 2
|Name| |Purchase Price| |soldPrice| |shippingPrice|
XYZ $4.00 $6.00 $2.00
---------------------------------------------------------------------------------------------
If you have any query, please feel free to ask.
Thanks a lot.

More Related Content

Similar to C programming tweak needed for a specific program.This is the comp.pdf

Hi,Please fidn the Answer.Sorting,h is Header .pdf
Hi,Please fidn the Answer.Sorting,h is Header .pdfHi,Please fidn the Answer.Sorting,h is Header .pdf
Hi,Please fidn the Answer.Sorting,h is Header .pdf
anandf0099
 
Fewd week5 slides
Fewd week5 slidesFewd week5 slides
Fewd week5 slides
William Myers
 
-- Reminder that your file name is incredibly important- Please do not.docx
-- Reminder that your file name is incredibly important- Please do not.docx-- Reminder that your file name is incredibly important- Please do not.docx
-- Reminder that your file name is incredibly important- Please do not.docx
Adamq0DJonese
 
05 JavaScript #burningkeyboards
05 JavaScript #burningkeyboards05 JavaScript #burningkeyboards
05 JavaScript #burningkeyboards
Denis Ristic
 
filesHeap.h#ifndef HEAP_H#define HEAP_H#includ.docx
filesHeap.h#ifndef HEAP_H#define HEAP_H#includ.docxfilesHeap.h#ifndef HEAP_H#define HEAP_H#includ.docx
filesHeap.h#ifndef HEAP_H#define HEAP_H#includ.docx
ssuser454af01
 
VTU DSA Lab Manual
VTU DSA Lab ManualVTU DSA Lab Manual
VTU DSA Lab Manual
AkhilaaReddy
 
Java codes output preliminary level
Java codes output preliminary levelJava codes output preliminary level
Java codes output preliminary levelDr. Vignes Gopal
 
JavaScript Closures for Dummies & JavaScript prototype, closures and OOP.
JavaScript Closures for Dummies & JavaScript prototype, closures and OOP.JavaScript Closures for Dummies & JavaScript prototype, closures and OOP.
JavaScript Closures for Dummies & JavaScript prototype, closures and OOP.
Jin-Hwa Kim
 
c++main.cpp#include iostream#include store.h#includ.docx
c++main.cpp#include iostream#include store.h#includ.docxc++main.cpp#include iostream#include store.h#includ.docx
c++main.cpp#include iostream#include store.h#includ.docx
humphrieskalyn
 
svelte-en.pdf
svelte-en.pdfsvelte-en.pdf
svelte-en.pdf
ssuser65180a
 
Say It With Javascript
Say It With JavascriptSay It With Javascript
Say It With Javascript
Giovanni Scerra ☃
 
#include fstream#include iostream#include cstdlib#includ.docx
#include fstream#include iostream#include cstdlib#includ.docx#include fstream#include iostream#include cstdlib#includ.docx
#include fstream#include iostream#include cstdlib#includ.docx
ajoy21
 
Flex lexer.h -c++-- flexlexer.h -- define interfaces f
Flex lexer.h  -c++-- flexlexer.h -- define interfaces fFlex lexer.h  -c++-- flexlexer.h -- define interfaces f
Flex lexer.h -c++-- flexlexer.h -- define interfaces f
aman39650
 
Bestpractices nl
Bestpractices nlBestpractices nl
Bestpractices nl
Wilfred Nas
 
Workshop 10: ECMAScript 6
Workshop 10: ECMAScript 6Workshop 10: ECMAScript 6
Workshop 10: ECMAScript 6
Visual Engineering
 
Write a program that converts an infix expression into an equivalent.pdf
Write a program that converts an infix expression into an equivalent.pdfWrite a program that converts an infix expression into an equivalent.pdf
Write a program that converts an infix expression into an equivalent.pdf
mohdjakirfb
 
Qprgs
QprgsQprgs
Symfony World - Symfony components and design patterns
Symfony World - Symfony components and design patternsSymfony World - Symfony components and design patterns
Symfony World - Symfony components and design patterns
Łukasz Chruściel
 
The purpose of this C++ programming project is to allow the student .pdf
The purpose of this C++ programming project is to allow the student .pdfThe purpose of this C++ programming project is to allow the student .pdf
The purpose of this C++ programming project is to allow the student .pdf
Rahul04August
 

Similar to C programming tweak needed for a specific program.This is the comp.pdf (20)

Hi,Please fidn the Answer.Sorting,h is Header .pdf
Hi,Please fidn the Answer.Sorting,h is Header .pdfHi,Please fidn the Answer.Sorting,h is Header .pdf
Hi,Please fidn the Answer.Sorting,h is Header .pdf
 
Fewd week5 slides
Fewd week5 slidesFewd week5 slides
Fewd week5 slides
 
-- Reminder that your file name is incredibly important- Please do not.docx
-- Reminder that your file name is incredibly important- Please do not.docx-- Reminder that your file name is incredibly important- Please do not.docx
-- Reminder that your file name is incredibly important- Please do not.docx
 
Day 1
Day 1Day 1
Day 1
 
05 JavaScript #burningkeyboards
05 JavaScript #burningkeyboards05 JavaScript #burningkeyboards
05 JavaScript #burningkeyboards
 
filesHeap.h#ifndef HEAP_H#define HEAP_H#includ.docx
filesHeap.h#ifndef HEAP_H#define HEAP_H#includ.docxfilesHeap.h#ifndef HEAP_H#define HEAP_H#includ.docx
filesHeap.h#ifndef HEAP_H#define HEAP_H#includ.docx
 
VTU DSA Lab Manual
VTU DSA Lab ManualVTU DSA Lab Manual
VTU DSA Lab Manual
 
Java codes output preliminary level
Java codes output preliminary levelJava codes output preliminary level
Java codes output preliminary level
 
JavaScript Closures for Dummies & JavaScript prototype, closures and OOP.
JavaScript Closures for Dummies & JavaScript prototype, closures and OOP.JavaScript Closures for Dummies & JavaScript prototype, closures and OOP.
JavaScript Closures for Dummies & JavaScript prototype, closures and OOP.
 
c++main.cpp#include iostream#include store.h#includ.docx
c++main.cpp#include iostream#include store.h#includ.docxc++main.cpp#include iostream#include store.h#includ.docx
c++main.cpp#include iostream#include store.h#includ.docx
 
svelte-en.pdf
svelte-en.pdfsvelte-en.pdf
svelte-en.pdf
 
Say It With Javascript
Say It With JavascriptSay It With Javascript
Say It With Javascript
 
#include fstream#include iostream#include cstdlib#includ.docx
#include fstream#include iostream#include cstdlib#includ.docx#include fstream#include iostream#include cstdlib#includ.docx
#include fstream#include iostream#include cstdlib#includ.docx
 
Flex lexer.h -c++-- flexlexer.h -- define interfaces f
Flex lexer.h  -c++-- flexlexer.h -- define interfaces fFlex lexer.h  -c++-- flexlexer.h -- define interfaces f
Flex lexer.h -c++-- flexlexer.h -- define interfaces f
 
Bestpractices nl
Bestpractices nlBestpractices nl
Bestpractices nl
 
Workshop 10: ECMAScript 6
Workshop 10: ECMAScript 6Workshop 10: ECMAScript 6
Workshop 10: ECMAScript 6
 
Write a program that converts an infix expression into an equivalent.pdf
Write a program that converts an infix expression into an equivalent.pdfWrite a program that converts an infix expression into an equivalent.pdf
Write a program that converts an infix expression into an equivalent.pdf
 
Qprgs
QprgsQprgs
Qprgs
 
Symfony World - Symfony components and design patterns
Symfony World - Symfony components and design patternsSymfony World - Symfony components and design patterns
Symfony World - Symfony components and design patterns
 
The purpose of this C++ programming project is to allow the student .pdf
The purpose of this C++ programming project is to allow the student .pdfThe purpose of this C++ programming project is to allow the student .pdf
The purpose of this C++ programming project is to allow the student .pdf
 

More from flashfashioncasualwe

How does the mutation rate of speciation in the Dobzhansky- Muller m.pdf
How does the mutation rate of speciation in the Dobzhansky- Muller m.pdfHow does the mutation rate of speciation in the Dobzhansky- Muller m.pdf
How does the mutation rate of speciation in the Dobzhansky- Muller m.pdf
flashfashioncasualwe
 
Hello. I need help fixing this Java Code on Eclipse. Please fix part.pdf
Hello. I need help fixing this Java Code on Eclipse. Please fix part.pdfHello. I need help fixing this Java Code on Eclipse. Please fix part.pdf
Hello. I need help fixing this Java Code on Eclipse. Please fix part.pdf
flashfashioncasualwe
 
Focus on Writing 4. Supporting a Point of View Do you think Social Se.pdf
Focus on Writing 4. Supporting a Point of View Do you think Social Se.pdfFocus on Writing 4. Supporting a Point of View Do you think Social Se.pdf
Focus on Writing 4. Supporting a Point of View Do you think Social Se.pdf
flashfashioncasualwe
 
Decision-Making Across the Organization The board of trustees of a lo.pdf
Decision-Making Across the Organization The board of trustees of a lo.pdfDecision-Making Across the Organization The board of trustees of a lo.pdf
Decision-Making Across the Organization The board of trustees of a lo.pdf
flashfashioncasualwe
 
Explain the experience of African-Americans in the South over the co.pdf
Explain the experience of African-Americans in the South over the co.pdfExplain the experience of African-Americans in the South over the co.pdf
Explain the experience of African-Americans in the South over the co.pdf
flashfashioncasualwe
 
During a diversity management session, a manager suggests that stereo.pdf
During a diversity management session, a manager suggests that stereo.pdfDuring a diversity management session, a manager suggests that stereo.pdf
During a diversity management session, a manager suggests that stereo.pdf
flashfashioncasualwe
 
Explain why a mycoplasma PCR kit might give a negative result when u.pdf
Explain why a mycoplasma PCR kit might give a negative result when u.pdfExplain why a mycoplasma PCR kit might give a negative result when u.pdf
Explain why a mycoplasma PCR kit might give a negative result when u.pdf
flashfashioncasualwe
 
Describe the difference between the MOV instruction and the LEA instr.pdf
Describe the difference between the MOV instruction and the LEA instr.pdfDescribe the difference between the MOV instruction and the LEA instr.pdf
Describe the difference between the MOV instruction and the LEA instr.pdf
flashfashioncasualwe
 
Explain how enzymes work, explaining the four major types of metabol.pdf
Explain how enzymes work, explaining the four major types of metabol.pdfExplain how enzymes work, explaining the four major types of metabol.pdf
Explain how enzymes work, explaining the four major types of metabol.pdf
flashfashioncasualwe
 
Develop an inventory management system for an electronics store. The .pdf
Develop an inventory management system for an electronics store. The .pdfDevelop an inventory management system for an electronics store. The .pdf
Develop an inventory management system for an electronics store. The .pdf
flashfashioncasualwe
 
Describe one event from your daily life when you have changed your o.pdf
Describe one event from your daily life when you have changed your o.pdfDescribe one event from your daily life when you have changed your o.pdf
Describe one event from your daily life when you have changed your o.pdf
flashfashioncasualwe
 
All answers must be in your own wordsProvide a good, understandabl.pdf
All answers must be in your own wordsProvide a good, understandabl.pdfAll answers must be in your own wordsProvide a good, understandabl.pdf
All answers must be in your own wordsProvide a good, understandabl.pdf
flashfashioncasualwe
 
Add to BST.java a method height() that computes the height of the tr.pdf
Add to BST.java a method height() that computes the height of the tr.pdfAdd to BST.java a method height() that computes the height of the tr.pdf
Add to BST.java a method height() that computes the height of the tr.pdf
flashfashioncasualwe
 
Write an awareness objective for a newly formed adolescent chemical .pdf
Write an awareness objective for a newly formed adolescent chemical .pdfWrite an awareness objective for a newly formed adolescent chemical .pdf
Write an awareness objective for a newly formed adolescent chemical .pdf
flashfashioncasualwe
 
which of these prokaryotes are most likely to be found in the immedi.pdf
which of these prokaryotes are most likely to be found in the immedi.pdfwhich of these prokaryotes are most likely to be found in the immedi.pdf
which of these prokaryotes are most likely to be found in the immedi.pdf
flashfashioncasualwe
 
2. Why is only one end point observed for citric acid even though it .pdf
2. Why is only one end point observed for citric acid even though it .pdf2. Why is only one end point observed for citric acid even though it .pdf
2. Why is only one end point observed for citric acid even though it .pdf
flashfashioncasualwe
 
10. Benefits and costs of International Trade Search for a newspap.pdf
10. Benefits and costs of International Trade  Search for a newspap.pdf10. Benefits and costs of International Trade  Search for a newspap.pdf
10. Benefits and costs of International Trade Search for a newspap.pdf
flashfashioncasualwe
 
Why does the pattern in a shift register shift only one bit position.pdf
Why does the pattern in a shift register shift only one bit position.pdfWhy does the pattern in a shift register shift only one bit position.pdf
Why does the pattern in a shift register shift only one bit position.pdf
flashfashioncasualwe
 
Use the Internet to identify three network firewalls, and create a t.pdf
Use the Internet to identify three network firewalls, and create a t.pdfUse the Internet to identify three network firewalls, and create a t.pdf
Use the Internet to identify three network firewalls, and create a t.pdf
flashfashioncasualwe
 
To vaccinate or not to vaccinate Is the influenza Virus vaccine Saf.pdf
To vaccinate or not to vaccinate Is the influenza Virus vaccine Saf.pdfTo vaccinate or not to vaccinate Is the influenza Virus vaccine Saf.pdf
To vaccinate or not to vaccinate Is the influenza Virus vaccine Saf.pdf
flashfashioncasualwe
 

More from flashfashioncasualwe (20)

How does the mutation rate of speciation in the Dobzhansky- Muller m.pdf
How does the mutation rate of speciation in the Dobzhansky- Muller m.pdfHow does the mutation rate of speciation in the Dobzhansky- Muller m.pdf
How does the mutation rate of speciation in the Dobzhansky- Muller m.pdf
 
Hello. I need help fixing this Java Code on Eclipse. Please fix part.pdf
Hello. I need help fixing this Java Code on Eclipse. Please fix part.pdfHello. I need help fixing this Java Code on Eclipse. Please fix part.pdf
Hello. I need help fixing this Java Code on Eclipse. Please fix part.pdf
 
Focus on Writing 4. Supporting a Point of View Do you think Social Se.pdf
Focus on Writing 4. Supporting a Point of View Do you think Social Se.pdfFocus on Writing 4. Supporting a Point of View Do you think Social Se.pdf
Focus on Writing 4. Supporting a Point of View Do you think Social Se.pdf
 
Decision-Making Across the Organization The board of trustees of a lo.pdf
Decision-Making Across the Organization The board of trustees of a lo.pdfDecision-Making Across the Organization The board of trustees of a lo.pdf
Decision-Making Across the Organization The board of trustees of a lo.pdf
 
Explain the experience of African-Americans in the South over the co.pdf
Explain the experience of African-Americans in the South over the co.pdfExplain the experience of African-Americans in the South over the co.pdf
Explain the experience of African-Americans in the South over the co.pdf
 
During a diversity management session, a manager suggests that stereo.pdf
During a diversity management session, a manager suggests that stereo.pdfDuring a diversity management session, a manager suggests that stereo.pdf
During a diversity management session, a manager suggests that stereo.pdf
 
Explain why a mycoplasma PCR kit might give a negative result when u.pdf
Explain why a mycoplasma PCR kit might give a negative result when u.pdfExplain why a mycoplasma PCR kit might give a negative result when u.pdf
Explain why a mycoplasma PCR kit might give a negative result when u.pdf
 
Describe the difference between the MOV instruction and the LEA instr.pdf
Describe the difference between the MOV instruction and the LEA instr.pdfDescribe the difference between the MOV instruction and the LEA instr.pdf
Describe the difference between the MOV instruction and the LEA instr.pdf
 
Explain how enzymes work, explaining the four major types of metabol.pdf
Explain how enzymes work, explaining the four major types of metabol.pdfExplain how enzymes work, explaining the four major types of metabol.pdf
Explain how enzymes work, explaining the four major types of metabol.pdf
 
Develop an inventory management system for an electronics store. The .pdf
Develop an inventory management system for an electronics store. The .pdfDevelop an inventory management system for an electronics store. The .pdf
Develop an inventory management system for an electronics store. The .pdf
 
Describe one event from your daily life when you have changed your o.pdf
Describe one event from your daily life when you have changed your o.pdfDescribe one event from your daily life when you have changed your o.pdf
Describe one event from your daily life when you have changed your o.pdf
 
All answers must be in your own wordsProvide a good, understandabl.pdf
All answers must be in your own wordsProvide a good, understandabl.pdfAll answers must be in your own wordsProvide a good, understandabl.pdf
All answers must be in your own wordsProvide a good, understandabl.pdf
 
Add to BST.java a method height() that computes the height of the tr.pdf
Add to BST.java a method height() that computes the height of the tr.pdfAdd to BST.java a method height() that computes the height of the tr.pdf
Add to BST.java a method height() that computes the height of the tr.pdf
 
Write an awareness objective for a newly formed adolescent chemical .pdf
Write an awareness objective for a newly formed adolescent chemical .pdfWrite an awareness objective for a newly formed adolescent chemical .pdf
Write an awareness objective for a newly formed adolescent chemical .pdf
 
which of these prokaryotes are most likely to be found in the immedi.pdf
which of these prokaryotes are most likely to be found in the immedi.pdfwhich of these prokaryotes are most likely to be found in the immedi.pdf
which of these prokaryotes are most likely to be found in the immedi.pdf
 
2. Why is only one end point observed for citric acid even though it .pdf
2. Why is only one end point observed for citric acid even though it .pdf2. Why is only one end point observed for citric acid even though it .pdf
2. Why is only one end point observed for citric acid even though it .pdf
 
10. Benefits and costs of International Trade Search for a newspap.pdf
10. Benefits and costs of International Trade  Search for a newspap.pdf10. Benefits and costs of International Trade  Search for a newspap.pdf
10. Benefits and costs of International Trade Search for a newspap.pdf
 
Why does the pattern in a shift register shift only one bit position.pdf
Why does the pattern in a shift register shift only one bit position.pdfWhy does the pattern in a shift register shift only one bit position.pdf
Why does the pattern in a shift register shift only one bit position.pdf
 
Use the Internet to identify three network firewalls, and create a t.pdf
Use the Internet to identify three network firewalls, and create a t.pdfUse the Internet to identify three network firewalls, and create a t.pdf
Use the Internet to identify three network firewalls, and create a t.pdf
 
To vaccinate or not to vaccinate Is the influenza Virus vaccine Saf.pdf
To vaccinate or not to vaccinate Is the influenza Virus vaccine Saf.pdfTo vaccinate or not to vaccinate Is the influenza Virus vaccine Saf.pdf
To vaccinate or not to vaccinate Is the influenza Virus vaccine Saf.pdf
 

Recently uploaded

Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
TechSoup
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
kaushalkr1407
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
SACHIN R KONDAGURI
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
TechSoup
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
timhan337
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
Jheel Barad
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
beazzy04
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
Anna Sz.
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Atul Kumar Singh
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
vaibhavrinwa19
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
joachimlavalley1
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
CarlosHernanMontoyab2
 

Recently uploaded (20)

Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
 

C programming tweak needed for a specific program.This is the comp.pdf

  • 1. C programming tweak needed for a specific program. This is the complete program up and running. except for one modification that my teacher is requiring but it is confusing me. The program needs to allocate disjoint memory and use that. right now im allocating a continous block of memory on the heap but I need it to do disjoing memory instead. // Purpose: Program will allow a reseller to save their sales and calculate their profits. // Also able to view highest profitable items and remove any sales they no longer want in their sales inventory. #define _CRT_SECURE_NO_WARNINGS #include #include #include #define PAUSE system("pause") #define CLS system("cls"); //#define FLUSH fflush(stdin); //////////////// SRUCTS BELOW ////////////////////////// typedef struct { char itemName[40]; float purchasePrice; float soldPrice; float shippingPrice; float ebayFee; float payPalFee; float profit; }SALES; ////////// FUNCTION PROTOTYPE BELOW ///////////// void addSale(SALES *Inventory, int *InventoryCounter); void displayMenu(int *InventoryCounter); void displayProfit(int *InventoryCounter, SALES *Inventory);
  • 2. void displaySales(int *InventoryCounter, SALES *Inventory); int getChoice(int *InventoryCounter); void searchSale(SALES* Inventory, int InventoryCounter); void sortProfits(SALES* Inventory, int InventoryCounter); void removeSale(SALES* Inventory, int *InventoryCounter); main() { int SIZE; int userChoice; int InventoryCounter = 0; //printf("********************* "); //printf("* Welcome Reseller! * "); //printf("********************* "); printf("Enter the size of todays inventory:"); scanf("%i", &SIZE); SALES *Inventory; Inventory = calloc(SIZE, sizeof(SALES));//Using dynamic memory to allocate space on the heap do { userChoice = getChoice(&InventoryCounter); switch (userChoice) { case 1:// Add a Sale if (InventoryCounter == SIZE) // statement checks so we dont exceed the size of the inventory user wants to enter. { printf("You Have Reached Max Inventory "); PAUSE; } else { addSale(&(Inventory[InventoryCounter]), &InventoryCounter); }
  • 3. break; case 2: // Display all sales records displaySales(&InventoryCounter, Inventory); PAUSE; break; case 3: // Display all profits sortProfits(Inventory, InventoryCounter); displayProfit(&InventoryCounter, Inventory); PAUSE; break; case 4: // Display Inventory searchSale(Inventory, InventoryCounter); break; case 5:// remove a sale removeSale(Inventory, &InventoryCounter); break; case 6: // Quit break; default: printf("Please choose a valid option "); PAUSE; break; }// end of switch } while (userChoice != 6); free(Inventory); } // End of main //////////////////////////////////////////// FUNCTIONS BELOW ////////////////////////////////////////////////// void addSale(SALES *Inventory, int *InventoryCounter)// Function that adds sale and calculates the fees in the background. { float payPalFee = 0; // variable to store the paypal fee from 1 sale float ebayFee = 0; // variable to store ebay fee for 1 sale
  • 4. /////////////// GETTING INVENTORY DETAILS //////////////// printf("Enter the Item name: "); scanf(" %[A-Z a-z]", Inventory->itemName); printf(" Enter the item's purchase price: "); scanf(" %f", &(Inventory->purchasePrice)); printf(" Enter the items Sold Price : "); scanf(" %f", &(Inventory->soldPrice)); printf(" Enter the item Shipping Price: "); scanf(" %f", &(Inventory->shippingPrice)); /////////////////////////////////////////////////////////// /////////////// Fees Calculated below //////////////// payPalFee = (Inventory->soldPrice) * (.03) + .30; // Calculating Paypals fee Which is 3% of sold price plus .30 cents ebayFee = (Inventory->soldPrice)* (.10); // Caluculating Ebays fee which is 10% of sold price Inventory->payPalFee = payPalFee; // Saving the paypal fee for this specific item in struct Inventory->ebayFee = ebayFee; // Saving the ebay fee for this specific item in struct // calculating the profit for this 1 secific item based on details provided (line below) // Inventory->profit = Inventory->soldPrice - Inventory->payPalFee - Inventory->ebayFee - Inventory->purchasePrice - Inventory->shippingPrice; (*InventoryCounter)++; // Incrementing Inventory counter ( amount of sales) } // End of addSale void searchSale(SALES* Inventory, int InventoryCounter) // function that searches for a sale by
  • 5. name { char name[100]; // array to hold item searched name char found = 'N'; // Flag variable int i; // loop control variable ////// Ask User for item name ////// printf("What item are you searching for? "); scanf("%s", name); for (i = 0; i < InventoryCounter; i++) { if (strcmp(name, Inventory[i].itemName) == 0)// returns 0 if item was found, then we can display the item details. { printf(" |Name|t|Purchase Price|t|soldPrice|t|Profit| "); printf(" %.6s ttt$%.2f tt$%.2f tt$%.2f ", Inventory[i].itemName, Inventory[i].purchasePrice, Inventory[i].soldPrice, Inventory[i].profit); found = 'Y';//flag changed to illustrate item was found PAUSE; }// end if statment }// end for loop if (found == 'N') // if strcmp does not return 0 and flag stays 'N' then item will not be in inventory { printf("Item not found "); PAUSE; } }// end search Sales function void displayProfit(int *InventoryCounter, SALES *Inventory) // Function that displays the profit details of each item. { int i; // loop control variable CLS;
  • 6. printf("|Name|t| Profit| "); for (i = 0; i < *InventoryCounter; i++)// loops through all the items and displays their name and profit detials. { printf("%st%.2f ", Inventory[i].itemName, Inventory[i].profit); } // End of for loop } // End of displayProfit void displayMenu(int *InventoryCounter) // Fucntion that displays the Main Menu { CLS; printf("******** Main Menu ********* "); printf("1. Add a sale. "); printf("2. Display all Inventory records. "); printf("3. Display all Inventory profits (high to low). "); printf("4. Search inventory for a specific item . "); printf("5. Remove a Sale from Inventory "); printf("6. Quit. "); printf("Current Sales: %i ", *InventoryCounter); printf("Enter your choice: "); } // End of displayMenu void displaySales(int *InventoryCounter, SALES *Inventory) // Fucntion that Displays all sales records { int i; // loop control variable CLS; printf(" |Name|tt|Purchase Price|t|soldPrice|tt|shippingPrice| "); for (i = 0; i < *InventoryCounter; i++) // loops through all the inventory and displays details { printf(" %.6s ttt$%.2f ttt$%.2f ttt $%.2f ", Inventory[i].itemName, Inventory[i].purchasePrice, Inventory[i].soldPrice, Inventory[i].shippingPrice); } // End of for loop } // End of displaySales
  • 7. int getChoice(int *InventoryCounter)// Function that returns the user Choice from menu { int result; displayMenu(InventoryCounter); while (getchar() != ' ') {}; scanf(" %i", &result); return result; } // End of getChoice void sortProfits(SALES *Inventory, int InventoryCounter)// Function that sorts all the profits from highest to lowest { int i, j;// loop control variable SALES temp;// temp place holder. for (i = 0; i < (InventoryCounter - 1); i++) { for (j = 0; j < InventoryCounter - i - 1; j++) { if (Inventory[j].profit < Inventory[j + 1].profit) { temp = Inventory[j]; Inventory[j] = Inventory[j + 1]; Inventory[j + 1] = temp; } } }// end for loop through all inventory }// End Sort Profits function void removeSale(SALES* Inventory, int *InventoryCounter) { char name[100];// char array to hold item searched name int i, j; // loop control variable char found = 'N';// Flag variable printf("What item do you want to remove? ");
  • 8. scanf("%s", name); for (i = 0; i < *InventoryCounter; i++) { if (strcmp(name, Inventory[i].itemName) == 0) //if strcmp returns 0 then item will be removed from inventory { for (j = i; j < *InventoryCounter - 1; j++) Inventory[j] = Inventory[j + 1]; (*InventoryCounter)--; printf(" Item Succesfully Removed "); found = 'Y'; PAUSE; }// end if statement }// end for loop if (found == 'N') // if strcmp does not return 0 and flag stays 'N' then item will not be in inventory { printf("Item not found "); PAUSE; }// end else statement }// end removeSale function Solution #define _CRT_SECURE_NO_WARNINGS #include #include #include #define PAUSE system("pause") #define CLS system("cls"); //#define FLUSH fflush(stdin); //////////////// SRUCTS BELOW //////////////////////////
  • 9. typedef struct SALESINFO { char itemName[40]; float purchasePrice; float soldPrice; float shippingPrice; float ebayFee; float payPalFee; float profit; }SALES; ////////// FUNCTION PROTOTYPE BELOW ///////////// void addSale(SALES *Inventory, int *InventoryCounter); void displayMenu(int *InventoryCounter); void displayProfit(int *InventoryCounter, SALES *Inventory); void displaySales(int *InventoryCounter, SALES *Inventory); int getChoice(int *InventoryCounter); void searchSale(SALES* Inventory, int InventoryCounter); void sortProfits(SALES* Inventory, int InventoryCounter); void removeSale(SALES* Inventory, int *InventoryCounter); main() { int SIZE; int userChoice; int InventoryCounter = 0; //printf("********************* "); //printf("* Welcome Reseller! * "); //printf("********************* "); printf("Enter the size of todays inventory:"); scanf("%i", &SIZE); //SALES *Inventory; struct SALESINFO *Inventory; Inventory=(struct SALESINFO *) malloc (SIZE * sizeof(struct SALESINFO)); //Inventory = calloc(SIZE, sizeof(SALES));//Using dynamic memory to allocate space on the heap
  • 10. do { userChoice = getChoice(&InventoryCounter); switch (userChoice) { case 1:// Add a Sale if (InventoryCounter == SIZE) // statement checks so we dont exceed the size of the inventory user wants to enter. { printf("You Have Reached Max Inventory "); PAUSE; } else { addSale(&(Inventory[InventoryCounter]), &InventoryCounter); } break; case 2: // Display all sales records displaySales(&InventoryCounter, Inventory); PAUSE; break; case 3: // Display all profits sortProfits(Inventory, InventoryCounter); displayProfit(&InventoryCounter, Inventory); PAUSE; break; case 4: // Display Inventory searchSale(Inventory, InventoryCounter); break; case 5:// remove a sale removeSale(Inventory, &InventoryCounter); break; case 6: // Quit break; default: printf("Please choose a valid option "); PAUSE; break; }// end of switch
  • 11. } while (userChoice != 6); free(Inventory); } // End of main //////////////////////////////////////////// FUNCTIONS BELOW ////////////////////////////////////////////////// void addSale(SALES *Inventory, int *InventoryCounter)// Function that adds sale and calculates the fees in the background. { float payPalFee = 0; // variable to store the paypal fee from 1 sale float ebayFee = 0; // variable to store ebay fee for 1 sale /////////////// GETTING INVENTORY DETAILS //////////////// printf("Enter the Item name: "); scanf(" %[A-Z a-z]", Inventory->itemName); printf(" Enter the item's purchase price: "); scanf(" %f", &(Inventory->purchasePrice)); printf(" Enter the items Sold Price : "); scanf(" %f", &(Inventory->soldPrice)); printf(" Enter the item Shipping Price: "); scanf(" %f", &(Inventory->shippingPrice)); /////////////////////////////////////////////////////////// /////////////// Fees Calculated below //////////////// payPalFee = (Inventory->soldPrice) * (.03) + .30; // Calculating Paypals fee Which is 3% of sold price plus .30 cents ebayFee = (Inventory->soldPrice)* (.10); // Caluculating Ebays fee which is 10% of sold price Inventory->payPalFee = payPalFee; // Saving the paypal fee for this specific item in struct Inventory->ebayFee = ebayFee; // Saving the ebay fee for this specific item in struct // calculating the profit for this 1 secific item based on details provided (line below) // Inventory->profit = Inventory->soldPrice - Inventory->payPalFee - Inventory->ebayFee - Inventory->purchasePrice - Inventory->shippingPrice; (*InventoryCounter)++; // Incrementing Inventory counter ( amount of sales) } // End of addSale void searchSale(SALES* Inventory, int InventoryCounter) // function that searches for a sale by name { char name[100]; // array to hold item searched name
  • 12. char found = 'N'; // Flag variable int i; // loop control variable ////// Ask User for item name ////// printf("What item are you searching for? "); scanf("%s", name); for (i = 0; i < InventoryCounter; i++) { if (strcmp(name, Inventory[i].itemName) == 0)// returns 0 if item was found, then we can display the item details. { printf(" |Name|t|Purchase Price|t|soldPrice|t|Profit| "); printf(" %.6s ttt$%.2f tt$%.2f tt$%.2f ", Inventory[i].itemName, Inventory[i].purchasePrice, Inventory[i].soldPrice, Inventory[i].profit); found = 'Y';//flag changed to illustrate item was found PAUSE; }// end if statment }// end for loop if (found == 'N') // if strcmp does not return 0 and flag stays 'N' then item will not be in inventory { printf("Item not found "); PAUSE; } }// end search Sales function void displayProfit(int *InventoryCounter, SALES *Inventory) // Function that displays the profit details of each item. { int i; // loop control variable CLS; printf("|Name|t| Profit| "); for (i = 0; i < *InventoryCounter; i++)// loops through all the items and displays their name and profit detials. { printf("%st%.2f ", Inventory[i].itemName, Inventory[i].profit); } // End of for loop
  • 13. } // End of displayProfit void displayMenu(int *InventoryCounter) // Fucntion that displays the Main Menu { CLS; printf("******** Main Menu ********* "); printf("1. Add a sale. "); printf("2. Display all Inventory records. "); printf("3. Display all Inventory profits (high to low). "); printf("4. Search inventory for a specific item . "); printf("5. Remove a Sale from Inventory "); printf("6. Quit. "); printf("Current Sales: %i ", *InventoryCounter); printf("Enter your choice: "); } // End of displayMenu void displaySales(int *InventoryCounter, SALES *Inventory) // Fucntion that Displays all sales records { int i; // loop control variable CLS; printf(" |Name|tt|Purchase Price|t|soldPrice|tt|shippingPrice| "); for (i = 0; i < *InventoryCounter; i++) // loops through all the inventory and displays details { printf(" %.6s ttt$%.2f ttt$%.2f ttt $%.2f ", Inventory[i].itemName, Inventory[i].purchasePrice, Inventory[i].soldPrice, Inventory[i].shippingPrice); } // End of for loop } // End of displaySales int getChoice(int *InventoryCounter)// Function that returns the user Choice from menu { int result; displayMenu(InventoryCounter); while (getchar() != ' ') {}; scanf(" %i", &result); return result; } // End of getChoice void sortProfits(SALES *Inventory, int InventoryCounter)// Function that sorts all the profits from highest to lowest
  • 14. { int i, j;// loop control variable SALES temp;// temp place holder. for (i = 0; i < (InventoryCounter - 1); i++) { for (j = 0; j < InventoryCounter - i - 1; j++) { if (Inventory[j].profit < Inventory[j + 1].profit) { temp = Inventory[j]; Inventory[j] = Inventory[j + 1]; Inventory[j + 1] = temp; } } }// end for loop through all inventory }// End Sort Profits function void removeSale(SALES* Inventory, int *InventoryCounter) { char name[100];// char array to hold item searched name int i, j; // loop control variable char found = 'N';// Flag variable printf("What item do you want to remove? "); scanf("%s", name); for (i = 0; i < *InventoryCounter; i++) { if (strcmp(name, Inventory[i].itemName) == 0) //if strcmp returns 0 then item will be removed from inventory { for (j = i; j < *InventoryCounter - 1; j++) Inventory[j] = Inventory[j + 1]; (*InventoryCounter)--; printf(" Item Succesfully Removed "); found = 'Y'; PAUSE; }// end if statement
  • 15. }// end for loop if (found == 'N') // if strcmp does not return 0 and flag stays 'N' then item will not be in inventory { printf("Item not found "); PAUSE; }// end else statement }// end removeSale function ------------------------- output sample:- ******** Main Menu ********* 1. Add a sale. 2. Display all Inventory records. 3. Display all Inventory profits (high to low). 4. Search inventory for a specific item . 5. Remove a Sale from Inventory 6. Quit. Current Sales: 0 Enter your choice: 1 Enter the Item name: XYZ Enter the item's purchase price: 4 Enter the items Sold Price : 6 Enter the item Shipping Price:2 ******** Main Menu ********* 1. Add a sale. 2. Display all Inventory records. 3. Display all Inventory profits (high to low). 4. Search inventory for a specific item . 5. Remove a Sale from Inventory 6. Quit. Current Sales: 1 Enter your choice: 2 |Name| |Purchase Price| |soldPrice| |shippingPrice| XYZ $4.00 $6.00 $2.00 --------------------------------------------------------------------------------------------- If you have any query, please feel free to ask.