intro to c programming assignment help

This is a discussion on intro to c programming assignment help within the C++ Programming forums, part of the General Programming Boards category; hey im just having a little trouble with the problem solving behind this assignment, can't quite get my loops to ...

  1. #1
    Registered User
    Join Date
    Oct 2010
    Posts
    3

    intro to c programming assignment help

    hey im just having a little trouble with the problem solving behind this assignment, can't quite get my loops to output and save what I want them too...
    anyways the goal is to use an input file with recorded tire revolutions/gas used to average gas mile and output a graph of it in 5 minute intervals.

    anywho, this is the code i've got so far... trying to have it average out 900 seconds into 3 5-min intervals
    Code:
    #include <stdio.h>
    
    #define PI 3.14159
    #define INCH_IN_MILE 63360
    
    int main() {
        
        FILE *ifp;
        int minTrip, intervals;
        double revs, gas, mileage[6], fueleffic, curMileage[60], totMileage, radius;
        
        // Open file and read in data
        ifp = fopen("sample.txt","r");
        fscanf(ifp, "%d%d", &minTrip, &radius);
        
        printf("min in trip = %d/n", minTrip);
        printf("radius = %d", radius);
        
        intervals = minTrip/5;
        int cases;
        for (cases=0; cases<intervals; cases++) {
            double totRevs = 0, totGas = 0;
            int i;
            for (i=1; i<=300; i++) {
                fscanf(ifp, "%lf%lf", &revs, &gas);
                totRevs = revs+totRevs;
                totGas = gas+totGas;
            }
            radius = radius/INCH_IN_MILE; // MAY BE INT!?!?
            mileage[cases] = (2*PI*radius*totRevs)/totGas;
            //printf("avg mil = %lf, %lf, %lf", mileage[0], mileage[1], mileage[2]);
    
        }
        
    system("PAUSE");
    return(0);        
    }
    and here is the sample file...
    Attached Files Attached Files

  2. #2
    Banned ಠ_ಠ's Avatar
    Join Date
    Mar 2009
    Posts
    687
    Quote Originally Posted by aargoo View Post
    hey im just having a little trouble with the problem solving behind this assignment, can't quite get my loops to output and save what I want them too...
    anyways the goal is to use an input file with recorded tire revolutions/gas used to average gas mile and output a graph of it in 5 minute intervals.

    anywho, this is the code i've got so far... trying to have it average out 900 seconds into 3 5-min intervals
    Code:
    #define INCH_IN_MILE 63360
    
        for (cases=0; cases<intervals; cases++) {
            
            radius = radius/INCH_IN_MILE; // MAY BE INT!?!?
        }
    and here is the sample file...

    this is going to get very, very small, very, very quickly, and no, it will never be an int when it shouldn't
    ╔╗╔══╦╗
    ║║║╔╗║║
    ║╚╣╚╝║╚╗
    ╚═╩══╩═╝

  3. #3
    Registered User
    Join Date
    Oct 2010
    Posts
    3
    also, here is the programming assignment in full if someone could hint me in the right direction:
    Attached Files Attached Files

  4. #4
    Registered User
    Join Date
    Oct 2010
    Posts
    3
    Quote Originally Posted by ಠ_ಠ View Post
    this is going to get very, very small, very, very quickly, and no, it will never be an int when it shouldn't
    ah ya, it should be out of the loop. regardless, still is giving me a crazy output :S
    Last edited by aargoo; 10-26-2010 at 06:51 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Menu
    By Krush in forum C Programming
    Replies: 17
    Last Post: 09-01-2009, 03:34 AM
  2. Assignment Operator, Memory and Scope
    By SevenThunders in forum C++ Programming
    Replies: 47
    Last Post: 03-31-2008, 07:22 AM
  3. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 03:39 PM
  4. Help with a pretty big C++ assignment
    By wakestudent988 in forum C++ Programming
    Replies: 1
    Last Post: 10-30-2006, 09:46 PM
  5. Replies: 1
    Last Post: 10-27-2006, 02:21 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21