I have almost everything done except a few things.
1. I can't seem to figure out how to RESET the program so that all values go back to default
2. Program always makes a beep noise after entering number (pounds) even though i'm telling it to break;
3. How do i stop a value from dividing by 0 at the start of the program (float avg)
I AM NOT ASKING FOR THE CODE, I want to try this on my own. So just tips.
Here is my code
/* PROGRAMMERS BLOCK
Author: XXXXXXXX
Student ID: 1234567890
Date: November 16th 2010
Description: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
TO DO's
- STOP THE BEEPING NOISE AFTER EACH INPUT
- FIX AVG (Beginning = UNDEFINED)
- MAKE A RESET LOOP IF R/r is ENTER
*/
// INCLUDE HEADERS
#include <stdio.h> // used for printf, scanf, getchar, puts
#include <stdlib.h> // used for system
/ DEFINE SECTION
#define A "Smarties " //Item A
#define AP "4.55" //Price of Item A per pound
#define B "Flour " //Item B
#define BP "1.5" //Price of Item B per pound
#define C "Soup " //Item C
#define CP "2.88" //Price of Item C per pound
#define D "Walnuts " //Item D
#define DP "5.25" //Price of Item D per pound
#define E "Rice " //Item E
#define EP "1.05" //Price of Item E per pound
#define F "Noodles " //Item F
#define FP "0.35" //Price of Item F per pound
#define G "Sugar " //Item G
#define GP "0.92" //Price of Item G per pound
#define H "CakeMix " //Item H
#define HP "1.45" //Price of Item H per pound
#define A_P 4.55 //Price of Item A per pound constants
#define B_P 1.5 //Price of Item B per pound constants
#define C_P 2.88 //Price of Item C per pound constants
#define D_P 5.25 //Price of Item D per pound constants
#define E_P 1.05 //Price of Item E per pound constants
#define F_P 0.35 //Price of Item F per pound constants
#define G_P 0.92 //Price of Item G per pound constants
#define H_P 1.45 //Price of Item H per pound constants
#define HST 0.13
// FUNCTION PROTOTYPES
void main_menu(); //Displays the menu and does all the calculations and then displays results
int main()
{
system("cls");
main_menu(); //Calls the function main_menu
// Wait for any key to be pressed
puts("");
puts("");
system("pause");
return 0;
}
void main_menu()
{
float pa=0.00,pb=0.00,pc=0.00,pd=0.00,pe=0.00,pf=0.00,pg=0.00,ph=0.00; // pa,b,c,d,e,f,g,h pounds of item at the beginning of the program
char choice; // Variable to store the choice entered by the user
do{ // do while loop
float sta=A_P*pa,stb=B_P*pb,stc=C_P*pc,std=D_P*pd,ste=E_P*pe,stf=F_P*pf,stg=G_P*pg,sth=H_P*ph; // sta,b,c,d,e,f,g,h = Subtotal of a,b,c,d,e,f,g,h
float stt=sta+stb+stc+std+ste+stf+stg+sth; // stt = Total of all subtotals
float totalpounds = pa+pb+pc+pd+pe+pf+pg+ph; // Total pounds
float avg=sta/totalpounds; // Average cost/lb
float hst= stt*HST; // HST Tax 13%
float totalcost=stt+hst; // Total Amount
puts("\t\tBULK FOOD STORE PROGRAM");
puts("");
puts("Item\tDescription\tCost/lb\t#Pounds\tSubtotal");
puts("");
printf("\nA\t"A"\t"AP"\t%.2f\t$ %.2f", pa, sta);
printf("\nB\t"B"\t\t"BP"\t%.2f\t$ %.2f", pb, stb);
printf("\nC\t"C"\t\t"CP"\t%.2f\t$ %.2f", pc, stc);
printf("\nD\t"D"\t"DP"\t%.2f\t$ %.2f", pd, std);
printf("\nE\t"E"\t\t"EP"\t%.2f\t$ %.2f", pe, ste);
printf("\nF\t"F"\t"FP"\t%.2f\t$ %.2f", pf, stf);
printf("\nG\t"G"\t\t"GP"\t%.2f\t$ %.2f", pg, stg);
printf("\nH\t"H"\t"HP"\t%.2f\t$ %.2f", ph, sth);
puts("");
printf("\nTotal Pounds = %.2f", totalpounds);
printf("\t SUBTOTAL $ %.2f", stt);
printf("\nAvg Cost/lb = %.2f", avg);
printf("\t HST Amount $ %.2f", hst);
puts("");
printf("\n\t\t\t TOTAL Amount $ %.2f", totalcost);
printf("\n\n Your choice (R to RESET, Q to quit) ==> ");
scanf("%c", &choice);
if (choice == 'q' || choice == 'Q') // If q/Q is entered as the choice, the program will quit
{
break;
}
else if (choice == 'r' || choice == 'R') // If r/R is entered as the choice, the program will reset all values
{
//RESET THE CODE
}
else
{
switch (choice) // switch for choices a-h and A-H
{
case 'a':
case 'A':
printf("\nHow many pounds of "A"would you like? ");
scanf("%f", &pa);
break;
case 'b':
case 'B':
printf("\nHow many pounds of "B"would you like? ");
scanf("%f", &pb);
break;
case 'c':
case 'C':
printf("\nHow many pounds of "C"would you like? ");
scanf("%f", &pc);
break;
case 'd':
case 'D':
printf("\nHow many pounds of "D"would you like? ");
scanf("%f", &pd);
break;
case 'e':
case 'E':
printf("\nHow many pounds of "E"would you like? ");
scanf("%f", &pe);
break;
case 'f':
case 'F':
printf("\nHow many pounds of "F"would you like? ");
scanf("%f", &pf);
break;
case 'g':
case 'G':
printf("\nHow many pounds of "G"would you like? ");
scanf("%f", &pg);
break;
case 'h':
case 'H':
printf("\nHow many pounds of "H"would you like? ");
scanf("%f", &ph);
break;
default:
puts("\a");
break;
}
}
}
while (1); // Infinite loop until program quits (choice == 'q' || choice == 'Q')
}
Thanks!
This post has been edited by Sushii: 17 November 2010 - 09:30 PM

New Topic/Question
Reply




MultiQuote







|