Could anyone help me? I have an assignment to do, learning how to program in C.
My task is to essentially create a cash register using C and using a template provided by my professor which all it has is a do while loop since we haven't covered it yet.
We've really only learned basic I/O stuff and if/elseif stuff, so if you could please leave assistance to only those things or close to it.
Code block #2 is the assignment outline, the chart is kind of messed up in the first part but that is the part I don't know how to setup.
I stopped my approach but what I thought to do was essentially, enter the product code and store that in code variable. Now, if the the product code is one of the 5 product codes, it will multiply the quantity by the listed price. But the next line is what I don't know how to do. Say the product code is, 12199 that we chose. How do we get the program to read that "1" and "2" are the first 2 numbers of the product code so that it prints "Produce bulks, Local fruits" on the next line?
ANY HELP IS GREAT! THANKS!
Code
#include <stdio.h>
// function prototypes
void PrintHeader();
void PrintFooter();
// PrintHeader: Display the header information of the receipt
// Input: no paramenters required, call it at the start of a new receipt
// Output: no return, simply outputs the appropriate header messages
void PrintHeader()
{
// TODO: Print the header lines, title, and the welcome message
printf("----------------------------------------------------------------------------------------------------------------\n\n");
printf(" _-===Windsor Market Farm Fresh ===-_\n\n");
printf("Welcome!\n");
}
// PrintFooter: Display the footer information of the receipt
// Input: no paramenters required, call it at the end of a receipt
// Output: no return, simply outputs the appropriate footer messages
void PrintFooter()
{
// TODO: Print the footer lines and thank you message
printf("----------------------------------------------------------------------------------------------------------------\n\n");
printf("THANK YOU FOR SHOPPING AT WINDSOR MARKET FARM FRESH, PLEASE COME AGAIN\n\n");
printf("----------------------------------------------------------------------------------------------------------------\n");
}
int main()
{
// TODO: Variable Declarations and Initializations here
int code=0; // use this variable to enter the product codes
float quantity;
float subTotal;
// Display Heading
PrintHeader();
// Main program loop
do
{
// TODO: Prompt for item, get the quantity, update sub-total;
// if the code is 00 you should compute totals and calculate the change.
printf("Enter Item Code: ");
scanf("%d", &code);
printf("Enter Quantity: ");
scanf("%f", &quantity);
}while(code != 0); // this loop will keep repeating until a code of zero is entered! (00=0)
// Display Footer
PrintFooter();
return 0;
}
Code
In this assignment you are asked to develop an interactive C program that implements an artificial calculator to generate a complete receipt for all shopping items. The idea is that the user first enters how much money he/she has saved and is ready to spend. The computer will then search for possible items from our list and provide the user with a revised list of items that he/she can afford. The complete list of shopping items is:
Department
Meaning
Example: corresponding display
1=Produce Bulk
1=local vegetables; 2=local fruits; 3=imports
12199 = Produce Bulk, local fruits, $1.99/lb
2=Produce Item
1=local vegetables; 2=local fruits; 3=imports
13350 = Produce Item, imports, $3.50 each
3=Floral
1=roses; 2=bouquet; 3=house plant
33999 = Floral, house plant, $9.99 each
4=Dairy
1=milk; 2=eggs; 3=butter; 4=yogurt
44099 = Dairy, yogurt, $0.99 each
5=Meats
1=beef; 2=chicken; 3=turkey; 4=pork; 5=rabbit
51299 = Meats, beef, $2.99/lb
6=Other
0=other item
60899 = Other, other item $8.99 each
7-9 unused yet
Program logic (Cash register logic): 1. The clerk types in the code for each item the customer is purchasing followed by the quantity.
2. As each item code is entered its ‘corresponding display’ is printed, and its price added to the accumulating total.
3. Once all the items are entered the cashier enters ‘00’ to compute the total with taxes at 7%.
4. The user provides the cash amount, the cashier enters the cash amount and the register calculates the change.
SAMPLE OUTPUT
----------------------------------------------------------------------
_-=== Windsor Market Farm Fresh ===-_
Welcome!
Enter Item code: 12199
Enter Quantity: 2.5
> Produce Bulk, local fruits, $1.99/lb @ 2.5 = $4.98
Enter Item code: 44099
Enter Quantity: 3
> Dairy, yogurt, $0.99 each @ 3 = $2.97
Enter Item code: 4444
<INVALID CODE, PLEASE TRY AGAIN>
Enter Item code: 00
----------------------------------------------------------------------
> SUB-TOTAL $7.95
> TAX@7% $0.56
----------------------------------------------------------------------
> TOTAL $4.45
----------------------------------------------------------------------
Enter CASH AMOUNT: 20
>CHANGE TO CUSTOMER DUE: $15.55
----------------------------------------------------------------------
THANK YOU FOR SHOPPING AT WINDSOR MARKET FARM FRESH, PLEASE COME AGAIN
----------------------------------------------------------------------