Question: C Program In/Out: Down below I have my Beer Inventory project and I need help with In & Out. Instead of reading the data from
C Program In/Out: Down below I have my Beer Inventory project and I need help with In & Out. Instead of reading the data from the keyboard (which is my code below), this time the program should read the from the file (beerinput.txt) and print the answers to another file (beeroutput.txt). How would I go about this? Thank you.
#include
int main(){
int inv1; int inv2; int inv3; //Setting all the variables for use. int inv4; int i; int totalAmnt;
printf("ID: Beer Brands "); //Prints the Beer ID's and Brands for the user printf("-- ----------- "); printf("1. Piels "); printf("2. Coors "); printf("3. Bud "); printf("4. Iron City ");
printf("Enter the on hands beer [cases]. "); //Stores the amount the user inputs //into the inventory integers. printf("Piels: "); scanf("%d", &inv1 ); printf("Coors: "); scanf("%d", &inv2); printf("Bud: "); scanf("%d", &inv3); printf("Iron City: "); scanf("%d", &inv4);
printf(" -Inventory Adjustments- "); //Creating a loop for the user to adjust inventory. while (i){ int totalAmnt = 0, i = 0; printf("Enter the beer ID or any letter to end: "); //Shows the user to enter ID# if (scanf("%d", &i) !=1) //or and letter to end to results. break; printf("Amount subtracted/purchased from on hands: "); if (scanf("%d", &totalAmnt) !=1) break;
if (i == 1) //Subtracts the total ID# cases from on hands inv1 -= totalAmnt; else if (i == 2) inv2 -= totalAmnt; else if (i == 3) inv3 -= totalAmnt; else if (i == 4) inv4 -= totalAmnt; else printf("!!INVALID ID!! "); //If entered a invalid #, will loop again. }
printf(" -End of Week Report- "); //Sums up the total cases on hands printf("Remaining of Piels: %d ", inv1); //subtracted from purchased. printf("Remaining of Coors: %d ", inv2); printf("Remaining of Bud: %d ", inv3); printf("Remaining of Iron City: %d ", inv4);
return 0; }
For example beerinput file How it should print out BUT only in a text beeroutput text file.

beerinp.ut-Notepad Fille Edit Fonat icw Hclp 500 500 500 500 ter5Beerln OutibinD utexe Iron Cily ron City: 596 200 InveriLory ndjusLmeriLs- Enter the beer ID o any letter to end: 1 nount subtracted/purchased fron ori hands:290 Enter the beer ID or any letter to nd: 2 nount subtracted/purchased fron ori hands:390 Enter the heer ID or any letter to nd: 3 nount subtracted/purchased fron or hands:190 Enter the heer ID or any letter to cnd: 1 nount subtracted/purchased fron o hands:500 Enter the heer TD or any letter to ond: h 300 100 500 End or werk Report eneining of Piels: 300 cnaining of Coors: 20 enining of Dud: 490 on ining of Tron (ity: roress rcturned xtion tine3.280 s ress any key to continue
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
