Thread: Help / Loops; input redirection from files

  1. #1
    Registered User
    Join Date
    Oct 2005
    Posts
    19

    Question Loops; input redirection from files

    We are given a data file containing these numbers( I saved as ontario.txt)

    101 7 43.5 56.3 23.2 66.6 87.1 56.1 11.1
    112 4 101.2 45.8 51.0 52.2
    119 1
    121 5 52.6 26.2 60.0 52.2 44.8
    114 0
    115 3 23.4 64.3 19.4

    column 1 is beach number
    column 2 is number of samples
    column 3 is the number of organisms per 100ml of water

    First I am supposed to have the beach number print and if the number of samples is less than 3 print "insufficient data" but if there is more than 3 have it caculate the average of the organisms collected, then if it is greater than >=50 say close beach, and if its under < 50 say open beach.

    (I'm using Quincy 99) I have to use teh If statement and nested If's as well...

    Thank-You!!!

  2. #2
    Registered User
    Join Date
    Oct 2005
    Posts
    19

    Please Help!!

    PLEASE HELP ME!!! I have been doing this for 1 hour

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Sure, I'll get right on it
    In the meantime, check the forum rules and the sig.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    Registered User
    Join Date
    Oct 2005
    Posts
    19

    submitting code

    How do I submit I c program on here?

  5. #5
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Copy and paste the relevant bits of code into the post. Use code tags (see my sig).
    Like so:

    Code:
    #include <stdio.h>
    
    int main(void)
    {
      return(0);
    }
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  6. #6
    Registered User
    Join Date
    Oct 2005
    Posts
    19

    Help

    Code:
    #include <stdio.h>
    
    int
    main (void)
    {
    	FILE *in;
    	int beach, samples;
    	double organisms, average;
    
    	in = fopen ("erie.txt", "r");
    
     scanf("%d,%d,%d", &beach, &samples, &organisms, &average);
            if(samples < 3)
                    printf ("insufficient data\n" );
            else if(samples >= 3)
                  fscanf (eriefile, "%d", &organisms);
                    average = 
      		{
    		if ( average >= 0.5)
    			printf ( "Closed\n" );
    		else
    		if ( average <= 0.5)
    			printf ( "Open\n" );
    
    		}
                    printf("Beach %d is )
    
    
    	return(0);
    }
    please help me...I need to allow c to look in for file of data

  7. #7
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Can you explain your question better please, I don't understand what you're asking.

    http://www.catb.org/~esr/faqs/smart-questions.html
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  8. #8
    Registered User
    Join Date
    Oct 2005
    Posts
    19
    o.k I am given this data file:
    101 7 43.5 56.3 23.2 66.6 87.1 56.1 11.1
    112 4 101.2 45.8 51.0 52.2
    119 1
    121 5 52.6 26.2 60.0 52.2 44.8
    114 0
    115 3 23.4 64.3 19.4

    1. Write the pseudocode for the following program definition: Calculate the mean level of E.Coli bacteria for a series of beaches. Make a descision to open or close the beach.
    - for each beach, there is a line of data in the file with the following fields separated by blanks, beach number, number of samples and one real number per sampling representing the number og orgainsims in 100ml of water
    - I have to calculate the average of the samples
    - If it is above 50 the beach needs to be closed, below 50 the beach stays open
    - If there are less than 3 samples, display "insufficient data".

  9. #9
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >>Write the pseudocode
    ... but you appear to be writing in C?! Which is it, pseudo or C ?
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  10. #10
    Registered User
    Join Date
    Oct 2005
    Posts
    19
    Program has to be in C...but we have to think of a pseudo code to start

  11. #11
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Code:
    101 7 43.5 56.3 23.2 66.6 87.1 56.1 11.1
    112 4 101.2 45.8 51.0 52.2
    119 1
    121 5 52.6 26.2 60.0 52.2 44.8
    114 0
    115 3 23.4 64.3 19.4
    Is this invalid data (the red)?
    It's saying there is a sample of data, yet it's missing.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Trouble with a lab
    By michael- in forum C Programming
    Replies: 18
    Last Post: 12-06-2005, 11:28 PM
  2. Reading Input Files
    By megsb3u in forum C++ Programming
    Replies: 4
    Last Post: 10-24-2005, 10:58 PM
  3. I Need To Know Some Things That I Can Put Into A Batch File
    By TheRealNapster in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 10-20-2003, 08:12 PM
  4. string input from files
    By jriano in forum C++ Programming
    Replies: 3
    Last Post: 06-01-2003, 01:08 PM
  5. input files in C
    By LWisne in forum C Programming
    Replies: 4
    Last Post: 09-30-2002, 06:24 AM