Thread: need urgent help

  1. #1
    Registered User
    Join Date
    May 2009
    Posts
    23

    Unhappy need urgent help

    hey!!!!! i find this very difficuilt please cud you help me write a program that reads numbers from a file and finds the sum, average, maximum and the minimum values.

    I got one program here , but i cannot post on this thread because something is wrong with my computer. This question is from a past year test paper and im finding difficuilties in solving this program.........please help.

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Sure. You need to
    1. Read the numbers
    2. Add them up
    3. Keep track of the maximum and the minimum
    4. Find the average

    Each bit should be separate from all the others and treated as such.

  3. #3
    Registered User
    Join Date
    Jan 2007
    Location
    Euless, TX
    Posts
    144
    Computer problems, eh? How did he manage to post this thread? Copy and paste didn't work? He didn't reel in Tabstop either! No integrity with this poster at all!

  4. #4
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    I got one program here
    So... what's your problem, then? We're not gonna write another one for you. Have you tried it yourself? Do you understand how to do it mathematically?

  5. #5
    Registered User
    Join Date
    Oct 2008
    Posts
    1,262
    I nominate this post for the worst "Please do my homework" post ever.

  6. #6
    Lost in the C ZaC's Avatar
    Join Date
    Jun 2008
    Location
    Italy
    Posts
    47
    The easiest program after "Hello word"... you should change work :P

  7. #7
    Registered User
    Join Date
    Jun 2009
    Posts
    486
    Code:
    #include <stdio.h>
    int main()
    {
      int c = 1;
      while (c)
      {
        printf("Do your own homework\n");
      }
    }
    Should do the trick

  8. #8
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    Shouldn't be that hard to write such a program, if a minimal amount of effort was spent in studying a good C resource, such as a good book.

    tabstop's solution can be made a little less complicated by adding the numbers as they are being read, thereby leaving out the mess of advanced memory management (although mathematical overflow could technically still occur if given input under certain conditions). To calculate the average would only entail keeping track of how many numbers have been read.

  9. #9
    Registered User
    Join Date
    May 2009
    Posts
    23

    Question

    Well i got one program here but when i compile it there's some errors with it so can you help in identifying some errors pleae.

    Code:
    #include<iostream>
    #include<stdlib.h>
    
    int main()
    {
        FILE *file_1;
        float average, max, min;
        float sum=0; int val; 
        int count=0;//1
        printf("**********This Program reads input from a file and then calculates:************\n\t\t\t the sum,\n\t\t\t average,\n\t\t\t maximunm and \n\t\t\t the minimum values.\n\n");
        printf("*******************************************************************************\n");  
        if ((file_1 = fopen("input.txt","r"))!= NULL)   //1
        {
              fscanf(file_1, "%d", &val); //1
              max= val;
              min = val;
              sum = val;
              count++;
           while(!(feof(file_1))) //1
           {
                
           }
           average = sum/count;
           printf("\n\tHere are the results:\n");//1
           printf("\t\tThe sum is %lf\n",sum);
           printf("\t\tNumber of values is %d\n", count);
           printf("\t\tAverage is %lf\n", average);
           printf("\t\tMaximum is %lf\n", max);
           printf("\t\tMinimum is %lf\n", min);
           fclose(file_1);
           if ((file_1 = fopen("result.txt", "w"))!= NULL)//1
           {
              fprintf(file_1,"%s\n","Here are the results:");//1
              fprintf(file_1,"%s\t", "The sum is");
             //write codes here
              fclose(file_1);
           }
        }
        else
            printf("Sorry,unable to open input.txt\n");
        printf("\t\t\t\t\tProgram Complied by:\n");
        printf("\t\t\t\t\t\t\tKaylash (18/05/09)\n\n");
        system("pause");
        return 0;      
    }

  10. #10
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    I'd expect tons of errors if that is a C program, since iostream is a C++ I/O header. Perhaps you meant to include stdio.h

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  11. #11
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by luke luvevou View Post
    when i compile it there's some errors with it so can you help in identifying some errors pleae.
    The problem is "the cat has got your tongue" (my mom used to say that when I would sulk).

    Why don't *you* tell us what the errors are, or make some kind of effort to explain yourself further?
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  12. #12
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Do you know what would really be a good idea? Actually saying what errors you're getting. I've been wanting to post this...

    How to Ask Smart Questions


    Quzah.
    Hope is the first step on the road to disappointment.

  13. #13
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by quzah View Post
    I've been wanting to post this...

    How to Ask Smart Questions
    And (wow!) look, that has been translated into "Bahasa Indonesian Brazilo-Portuguese Chinese Czech Danish Dutch Estonian Finnish French Georgian German Greek Hebrew Hungarian Italian Japanese Polish Portuguese Romanian Russian Serbian Spanish Swedish Thai Turkish".

    Now I can easily figure out how to say "Try to find an answer by inspection or experimentation" in Estonian, which is something I have always wanted to do.

    I think maybe this one would be good in Brazilo-Portuguese:
    We've found by experience that people who are careless and sloppy writers are usually also careless and sloppy at thinking and coding (often enough to bet on, anyway). Answering questions for careless and sloppy thinkers is not rewarding; we'd rather spend our time elsewhere.

    So expressing your question clearly and well is important. If you can't be bothered to do that, we can't be bothered to pay attention.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  14. #14
    Registered User
    Join Date
    May 2009
    Posts
    23

    Talking

    ok i have identify the errors my self after rewriting the program thanks for no help

  15. #15
    Registered User
    Join Date
    Aug 2008
    Location
    Belgrade, Serbia
    Posts
    163
    Hahaha, legendary! Good job then.
    Vanity of vanities, saith the Preacher, vanity of vanities; all is vanity.
    What profit hath a man of all his labour which he taketh under the sun?
    All the rivers run into the sea; yet the sea is not full; unto the place from whence the rivers come, thither they return again.
    For in much wisdom is much grief: and he that increaseth knowledge increaseth sorrow.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. display character size...(quite urgent..)
    By karthi in forum C Programming
    Replies: 10
    Last Post: 07-11-2007, 09:42 PM
  2. beginner plzz help urgent
    By sara101 in forum C Programming
    Replies: 11
    Last Post: 01-14-2007, 10:38 PM
  3. Linked List Need Help Urgent
    By ykchua in forum C Programming
    Replies: 5
    Last Post: 08-17-2004, 02:57 PM