Question
So I have my Beer Brand project down below, however I am trying to do I/O with it. Instead of reading the data from the
So I have my Beer Brand project down below, however I am trying to do I/O with it. Instead of reading the data from the keyboard, this time the program should read the provided file (beerinput.txt) and print the answers to another file (beeroutput.txt). How would I go about this? For example .txt file contains:
500 500 500 500 1 100 2 200 3 100 4 200 -------------
C Program Below
#include #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; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started