{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Homework2-2

# Homework2-2 - fscanf(fpin"%d"&quarters/get...

This preview shows pages 1–2. Sign up to view the full content.

Homework #2 /* * Program by Justin Waters * Inputs: * Outputs: * Description: determines the value of a collection of coins. * */ #include <stdio.h> int main (void) { char first, middle, last; //input - 3 initials int pennies, nickels; //input - count of each coin type int dimes, quarters; //input - count of each coin type int change; //output - change amount int dollars; //output - dollar amount int total_cents; //total cents FILE *fpin, *fpout; //declare source files fpin = fopen("in.txt","r"); //open in file fpout = fopen("out.txt","w"); //open/create out file fscanf(fpin, "%d", &pennies); //get pennies from file fscanf(fpin, "%d", &nickels); //get nickels from file fscanf(fpin, "%d", &dimes); //get dimes from file

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: fscanf(fpin, "%d", &quarters); //get quarters from file /* Get and display customer's initials from in.txt file.*/ fscanf(fpin, "%c%c%c", &first, &middle, &last); fprintf(fpout, "Hello %c%c%c, let's see what your coins are worth.\n", first, middle, last); /*calculate total cents*/ total_cents = 25 * quarters + 10 * dimes + 5 * nickels + pennies; //seperate dollars from cents dollars = total_cents / 100; change = total_cents % 100; /*write calculated output to seperate out file*/ fprintf(fpout, "\nYour coins are worth %d dollars and %d cents. \n", dollars, change); fclose(fpin); //close in text file fclose(fpout); //close output text file return (0); }...
View Full Document

{[ snackBarMessage ]}