Problem For School - Finding Average

Discussion in 'Programming General' started by DeepSnow, Oct 6, 2009.

Problem For School - Finding Average
  1. Unread #1 - Oct 6, 2009 at 4:37 PM
  2. DeepSnow
    Joined:
    Jun 30, 2009
    Posts:
    232
    Referrals:
    0
    Sythe Gold:
    0

    DeepSnow Active Member

    Problem For School - Finding Average

    Hey, this should be simple for most of you;

    Code:
    #include <stdio.h>
    int main()
    
    {
    int i;
    for(i = 0; i<10; i++)
     {
      printf("%d\n", i);
     } 
    return(0);
    }
    
    Now using a "for" loop or something similar to that one, write a program that prompts the user for how many numbers they wish to average, count up the numbers they typed in, and average them. I believe it will need to be functionless, but you have to declare some crap, I don't know. Printf and Scanf.

    We are using something called C Sharp? But apparently it's pretty much C. We program in VI while connected to a Linux machine. I've been doing good up till shortly, when we had to make a simple calculator. I couldn't submit anything and am now 400/500 points, or a 80 percent. Even getting 100 on this next assignment will bring me to an 83, this is the one class I am not doing well in, and I will not fucking fail an elective.

    Payment may be possible, as I said, I do not understand this shit and will most likely be coming back here for more assistance. [email protected] or nightmare3695 AIM, or just post back here. To be honest, I don't need help, yet just the entire completed code I can copy into notepad. If you have some weird issue with getting paid for writing a code, spill out how to start this. And I mean be basic, I understand basic, and that's it.

    Thanks

    *and jesus, be basic with writing the code too. It can't look too much like something I ripped off the internet. Because that stuff is available, but uses weird ass shit we don't know yet.
     
  3. Unread #2 - Oct 15, 2009 at 1:12 PM
  4. tofurocks
    Joined:
    Nov 8, 2008
    Posts:
    2,344
    Referrals:
    2
    Sythe Gold:
    0

    tofurocks Iloveroy

    Problem For School - Finding Average

    Still need this?
    I will write it for you when I get home, in school ATM.
     
  5. Unread #3 - Oct 15, 2009 at 5:35 PM
  6. Swan
    Joined:
    Jan 23, 2007
    Posts:
    4,957
    Referrals:
    0
    Sythe Gold:
    0
    Sythe's 10th Anniversary Member of the Month Winner

    Swan When They Cry...
    Retired Global Moderator

    Problem For School - Finding Average

    C# is vastly different to C. C# is more akin to Java than anything, and runs upon the .Net framework.

    Have you ever actually tried to learn this stuff before? It's extremely basic stuff. Perhaps you haven't been paying attention in class. If so, you probably deserve to fail. You sound like you're making a demand rather than asking for help. The internet is not your army, so you could at least be polite.

    You're going to need to say more than that or you'll seriously confuse people. Do you mean you need to include the stdio header to use printf() and scanf()?

    I'm going to school soon, hence I won't have time to show you how to do this right now.
     
  7. Unread #4 - Oct 16, 2009 at 9:22 PM
  8. d great one
    Joined:
    Nov 4, 2007
    Posts:
    930
    Referrals:
    2
    Sythe Gold:
    0

    d great one Apprentice

    Problem For School - Finding Average

    If you are using a C#, you can do it in the console.

    And write it Console.Write("Enter how many average you want to compute: ");

    Then follows the loop.
    I can do this, but you aren't nice to begin with asking for help.
    Maybe a little nicer would make people help you.
     
  9. Unread #5 - Oct 16, 2009 at 11:10 PM
  10. WCCobra
    Joined:
    Oct 7, 2009
    Posts:
    7
    Referrals:
    0
    Sythe Gold:
    0

    WCCobra Newcomer

    Problem For School - Finding Average

    Code:
    using System;
    
    namespace Application1
    {
        class Program
        {
            static void Main(string[] args)
            {
                double i = 0;
                double sum = 0;
    
                for (i = 0; i < 10; i++)
                {
                    sum = sum + i;
                }
    
                Console.WriteLine(sum / i);
            }
        }
    }
    
    
    Can't get much more basic looking than that. Suggest reading through some beginners guides to understand the C# code before you turn it in.
     
  11. Unread #6 - Oct 17, 2009 at 6:42 PM
  12. super_
    Joined:
    Dec 20, 2008
    Posts:
    91
    Referrals:
    0
    Sythe Gold:
    0

    super_ Member

    Problem For School - Finding Average

    80% is BAD? Are you retarded? You deserve to fail... but I am feeling generous.
    Code:
    #include <stdio.h>
    
    main() {
        int num_count;
        printf("input # of numbers to average: ");
        scanf("%d", &num_count);
    
        int i;
        int sum = 0;
        for (i = 0; i < num_count; ++i) {
            int input;
            scanf("%d", &input);
            sum += input;
        }
    
        printf("average: %d\n", sum / num_count);
        return 0;
    }
    
    note the average is calculated using integer arithmetic, and not floating point; it is not all too accurate. it prompts for the number of numbers to average, and then you input the numbers and hit enter after each:
    Code:
    input # of numbers to average: 2
    1
    3
    average: 2
    
     
  13. Unread #7 - Dec 1, 2009 at 6:35 AM
  14. ukrebel
    Joined:
    Nov 6, 2005
    Posts:
    196
    Referrals:
    1
    Sythe Gold:
    15

    ukrebel Active Member

    Problem For School - Finding Average

    So do you want it coded in C# or C?
     
  15. Unread #8 - Jan 11, 2010 at 11:31 AM
  16. KB2486
    Joined:
    Aug 21, 2009
    Posts:
    172
    Referrals:
    0
    Sythe Gold:
    0

    KB2486 Active Member

    Problem For School - Finding Average

    You dont need to declare int input inside loop, just put outside loop. Scanf function will override the lastest value every loop count.
     
< quick help, easy script, minor error | Program help >

Users viewing this thread
1 guest


 
 
Adblock breaks this site