// Arup Guha
// 9/21/2011
// Illustrates how to read from a file and write to a file.
#include <stdio.h>
#include <math.h>

int main() {

    // Open both files.
    FILE* ifp;
    ifp = fopen("sales.txt", "r");

    FILE* ofp;
    ofp = fopen("salesout.txt", "w");

    // Read in the number of students and the prices of the three
    // items.
    int numstudents;
    fscanf(ifp, "%d", &numstudents);

    double price1, price2, price3;
    fscanf(ifp, "%lf%lf%lf", &price1, &price2, &price3);

    // Loop through each student.
    int i;
    for (i=1; i<=numstudents; i++) {

        // Get how many boxes they sold.
        int numbox1, numbox2, numbox3;
        fscanf(ifp, "%d%d%d", &numbox1, &numbox2, &numbox3);

        // Calculate their gross revenue and print to the output file.
        double money = numbox1*price1 + numbox2*price2 + numbox3*price3;
        fprintf(ofp, "Student %d made $%.2lf.\n", i, money);
    }

    fclose(ifp);
    fclose(ofp);

    return 0;
}
