Homework2-2 - fscanf(fpin, "%d",...

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

View Full Document Right Arrow Icon
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
Background image of page 1

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

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: fscanf(fpin, &quot;%d&quot;, &amp;quarters); //get quarters from file /* Get and display customer's initials from in.txt file.*/ fscanf(fpin, &quot;%c%c%c&quot;, &amp;first, &amp;middle, &amp;last); fprintf(fpout, &quot;Hello %c%c%c, let's see what your coins are worth.\n&quot;, 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, &quot;\nYour coins are worth %d dollars and %d cents. \n&quot;, dollars, change); fclose(fpin); //close in text file fclose(fpout); //close output text file return (0); }...
View Full Document

Page1 / 2

Homework2-2 - fscanf(fpin, &amp;amp;quot;%d&amp;amp;quot;,...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online