Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In C language (printf not <<cout>>) The first thing the program needs to do is t

ID: 3881321 • Letter: I

Question

In C language (printf not <<cout>>)

The first thing the program needs to do is to display a menu, with the name of my business, the word “Menu” and a list of items and prices.

The price for my items is shown below. Put these amounts in constants and use the constants throughout the program:

Hot Dogs - $1.50

Chips - $.75

Drinks - $1.25

After displaying the menu, the program needs to ask the customer how many of each item they would like to purchase (Input)

Then the program needs to calculate the various amounts that will be displayed on the receipt (Process)

Finally, the program needs to display the receipt (Output). The receipt should show how many of each item was purchased and the amount for that many items. Then the receipt needs to show the sub-total for the bill. Tax is calculated based on the sub-total. We are currently charging 8% sales tax – put that value in a constant and use the constant in the program. Calculate the amount of sales tax and display both the sales tax percent and the amount. Finally, display the total amount the customer must pay for their food and drinks, and tell them “Thank you for your order!”.

Hints:

The menu is just a set of printf() statements

Use a tab (" ") to correctly place the 1st line of the menu (“GEORGE’S HOT DOGS”)

Use tabs and spaces to place the remaining lines of the menu (use spaces between the item name and the dash before the price)

Follow the 3 steps of the Information Processing Cycle – Input, Processing, and Output

Have a blank line after the menu, another blank line between the inputs and the output, and another blank line after the total

Use a tab to separate the item name column from the item price column in the receipt

Use dashes (“-“) to create the lines above the sub-total and the total

Use "%%" to display the percent sign And remember:

All variable names must be at least 2 words and in lower camelCase

Constant names are written in ALL_CAPS

Format all amounts to 2 decimal places (dollar and cents)

Don’t forget the dollar sign before the amount

Format the sales tax percentage to 1 decimal place, and don’t forget the percent sign

Separate your program output from the “Press any key…” with a blank line

Example Run: (The numbers in bold will be the users input)

GEORGE'S HOT DOGS

*** MENU ***

Hot Dog - $1.50 Chips - $0.75 Drink - $1.25

How many hot dogs would you like? 3 How many bags of chips would you like? 1 How many drinks would you like? 2

Hot Dogs (3) $4.50 Chips (1) $0.75 Drinks (2) $2.50 ------------- ------- Sub-Total $x.xx Tax (@8.0%) $x.xx ---------------- ------ Total $x.xx

Thank you for your order!

The example run shows EXACTLY how your program input and output will look.

Explanation / Answer

#include #include #include "valid.c"struct purch_detail { char item_desc[20]; int unit_price; int qty; }; void display(); void entryData(); void readFile(); void getName(char *str); void getWriteFileName(char *); void getReadFileName(char *); void getzeroInteger(char *_chr, int *_value); int count=0; int total_price=0; int total_amt=0; char option; char filename [14]; FILE *fp; struct purch_detail *pd_ptr, *tmptr; void main() { clrscr(); pd_ptr = (struct purch_detail *) malloc(sizeof(struct purch_detail) * 10); tmptr = pd_ptr; printf(" Do you want to create the data file type 'y' for yes and 'n' for no."); scanf("%c", &option); fflush(NULL); if( option == 'y' || option == 'Y') { printf(" You can generate bill of maximum 10 item. "); getWriteFileName(filename); display(); } elseif( option == 'n' || option == 'N') { getReadFileName(filename); readFile(); } getch(); } void entryData() { while(1) { printf(" Enter item name : "); getName(tmptr->item_desc); getPosInteger("Enter unit price of the item : ", &tmptr->unit_price); getzeroInteger("Enter no of qty purchased : ", &tmptr->qty); if(tmptr->qty == 0) break; count ++; if (count >= 10) break; /* if ( count % 2 == 0) if ( (pd_ptr = (struct purch_detail *) realloc(pd_ptr, sizeof(struct purch_detail) * 2)) == NULL) { printf("Realloc failed. No enough memory available."); break; } */ tmptr++; } } void display() { tmptr = pd_ptr; fprintf(fp," Item Unit Price Quantity Total Price "); fprintf(fp," ______________________________________________________"); printf(" Item Unit Price Quantity Total Price "); printf(" ______________________________________________________"); while(1) { total_price = tmptr->unit_price * tmptr->qty ; fprintf(fp, " %-20s %4d %4d %5d", tmptr->item_desc, tmptr->unit_price, tmptr->qty, total_price); printf(" %-20s %4d %4d %5d", tmptr->item_desc, tmptr->unit_price, tmptr->qty, total_price); //printf(""); total_amt += total_price; count--; if ( count = 20 ) break; } fflush(NULL); if(errorflag) getName(str); *getstr=''; } void getzeroInteger(char *_chr, int *_value) { float tempval =1; int _ival=0; printf(" %s", _chr); _scaint = scanf("%f", &tempval); fflush(NULL); if ( _scaint != 0 ) { _ival = tempval; if ( tempval < 0 ) { printf("%s", " You should enter value greater then or equal to zero. Enter the value again..."); getzeroInteger(_chr, _value); } elseif ( _ival != tempval) { printf("%s", " Error(decimal value). It will be truncated the digit after the percision. Enter integer number only."); getzeroInteger(_chr, _value); } elseif( ! ( (tempval >= -32768 ) && (tempval