Question: I am trying to take a C programming program and add functions to it , this is the original working program / * THIS PROGRAM

I am trying to take a C programming program and add functions to it, this is the original working program
/* THIS PROGRAM DOES NOT USE FUNCTIONS; THE TASK IS TO RE-WRITE IT USING FUNCTIONS */
/*Markup.c by CIS 1852024
Input: Keyboard
Output: Screen
This program calculates markup price of an inventory item. Items are marked up by 44%.
An item count and grand total of the marked up values is accumulated and printed at the end
of the program. This program will include separate functions for: heading, inputs,
processing and outputs after it is restructured using functions.
*/
#include
int main (void){
/* Declaration */
int itemNo=0, itemCount=0;
float cost=0.0f, markedup=0.0f, grandTotal =0.0f;
char again ='Y';
/* Heading */
printf("Markup Calculator by You
");
/* Begin Loop */
while (again =='Y'|| again =='y'){
/* Input Section */
do {
/* Validate entry */
printf("
Enter Item Number (101-999)");
scanf("%d", &itemNo);
if (itemNo <101|| itemNo >999){
printf("Item Number not accepted, enter an Item Number 101-999
");
}
} while (itemNo <101|| itemNo >999);
printf("Enter the cost of the inventory item ");
scanf("%f", &cost);
/* Processing Section */
markedup = cost *1.44f; //calculate markup
/* Accumulate count, total and loop */
itemCount++;
grandTotal += markedup;
/* Output Section */
printf("
The unit cost for item %d is %.2f
", itemNo, cost);
printf("The marked up sales amount is %.2f
", markedup);
/* Prompt user to determine if loop should continue */
printf("Enter another item? Enter Y or N ");
scanf ("%c", &again); // note the space in the conversion specifier
}/*End Loop */
/* Print count, final total */
printf("
Item Count: %d
", itemCount);
printf("
Grand Total of all marked up items: $%.2f
", grandTotal);
/* End program */
return 0;
}
This is my attempt to add functions to it, would someone please help me?
/* THIS PROGRAM DOES NOT USE FUNCTIONS; THE TASK IS TO RE-WRITE IT USING FUNCTIONS */
/*Markup.c by CIS 1852024
Input: Keyboard
Output: Screen
This program calculates markup price of an inventory item. Items are marked up by 44%.
An item count and grand total of the marked up values is accumulated and printed at the end
of the program. This program will include separate functions for: heading, inputs,
processing and outputs after it is restructured using functions.
*/
#include
// Prints Heading/Welcome Message
void printHeading(void);
// Gets item number from user
int Number(void);
//Gets item cost from user
float Cost(void);
/*Processing and calculating markup for a single item*/
float outputMarkup(float);
// Printing markup cost for a single item
void printmarkup(float );
int main (void){
/* Declaration */
int itemNo=0, itemCount=0;
float cost=0.0f, markedup=0.0f, grandTotal =0.0f;
char again ='Y';
// Heading/Welcome Message
printHeading();
/* Begin Loop */
while (again =='Y'|| again =='y'){
// get item number
itemNo = Number();
//get item cost
cost = Cost();
// get markedup
markedup = outputMarkup(cost);
// accumulate grand total and count
itemCount++;
grandTotal += markedup;
//**** print markup
printmarkup(markedup);
/* Prompt user to determine if loop should continue */
printf("Enter another item? Enter Y or N ");
scanf ("%c", &again); // note the space in the conversion specifier
}
/* Print count, final total */
//printf("
------------------
");
printf("
Item Count: %d
", itemCount);
printf("
Grand Total of all marked up items: $%.2f
", grandTotal);
/* Heading */
printf("Markup Calculator by You
");
/* End program */
return 0;
}
// Definitions
//Print heading welcome message
void printHeading(void){
// display heading
printf("Markup Calculator by Sarah Place
");
}
/* Input Section */
/*Getting the item number from the user*/
int Number(void){
int itemNo;
do {
/* Validate entry */
printf("
Enter Item Number (101-999)");
scanf("%d", &itemNo);
if (itemNo <101|| itemNo >999){
printf("Item Number not accepted, enter an Item Number 101-999
");
}
} while (itemNo <101|| itemNo >999);
return itemNo;
}
//Getting cost of inventory item
float Cost(void){
float cost=0.0f;
printf("Enter the cost of the inventory item ");
scanf("%f", &cost);
return cost;
}
/* Processing Section */
float outputMarkup =(float Cost)
{
float markup=0.0f;
markup = cost *1.44f;
return outputMarkup;
}
/* Output Section */
printf("
The unit cost for item %d is %.2f
", itemNo, cost);
printf("The marked up sales amount is %.2f
", markedup);
}/*End Loop */

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!