Excuse me.I am a new member. I need a helping in C language

This is a discussion on Excuse me.I am a new member. I need a helping in C language within the C Programming forums, part of the General Programming Boards category; Hello Thank you for this good forum I am really so happy I am one of its members now.. First, ...

  1. #1
    Registered User
    Join Date
    Jan 2010
    Posts
    1

    Smile Excuse me.I am a new member. I need a helping in C language

    Hello

    Thank you for this good forum
    I am really so happy I am one of its members now..

    First, I think it's important to say: The english language is not my native language. So, I am sorry if you find any spelling or grammer mistakes.
    I am trying to improve my english language as much as I can and I will be gratefull if you help me.

    ***

    I am a university student
    freshmen - level 1
    I am studing Computer engineering (Not in my native language. I study it in english language).

    This is the first course I study programming language.
    We are studying C language basic rules.

    ***

    I faced a small problem in Arrays.

    This was the question:

    * Develop a complete program that will accept 5 integer numbers from the user and then print the sum of all the numbers on the screen. Use a 1-dimension array named numT to keep all the numbers. The example of interaction and output are as follows:

    Please enter number 1
    3
    Please enter number 2
    5
    Please enter number 3
    4
    Please enter number 4
    7
    Please enter number 5
    9
    The total number of all number entered is 28


    ****


    I wrote my code and the compiling successed
    but when I run the program, the last statement (the total number entered) gives my a garbage number.
    I thought there was a mistake in initializing ( sum ) but I didn't know where.

    this was my code:

    Code:
    #include <stdio.h>
    
    void main()
    {
    int a[5]={0};
    int i;
    int sum=0;
    for(i=0;i<5;i++)
    a[i]=i+1;
    for(i=0;i<5;i++)
    {
    printf("Please enter number %d\n",i+1);
    scanf("%d",&a[i]);
    }
    sum = sum + a[i];
    printf("The total number of all number entered is %d",sum);
    }


    I wish some body help me..

    I am waiting..

    Thank you very much..

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,555
    Aside from the void main (see the FAQ), your poor indentation is hiding the problem.

    Code:
    #include <stdio.h>
    
    void main()
    {
      int a[5]={0};
      int i;
      int sum=0;
      for(i=0;i<5;i++)
        a[i]=i+1;
      for(i=0;i<5;i++)
      {
        printf("Please enter number %d\n",i+1);
        scanf("%d",&a[i]);
      }
      sum = sum + a[i];
      printf("The total number of all number entered is %d",sum);
    }
    See where the sum is calculated?
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Welcome to the forum, Computery.

  4. #4
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Katy, Texas
    Posts
    2,309
    Wow, he got 14 (as of now) replies over at devshed.
    Excuse me.I am a new member. I need a helping in C language - Dev Shed
    Mac and Windows cross platform programmer. Ruby lover.

    Quote of the Day
    12/20: Mario F.:I never was, am not, and never will be, one to shut up in the face of something I think is fundamentally wrong.

    Amen brother!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Menu Item Caption - /a for right aligned Accelerator?
    By JasonD in forum Windows Programming
    Replies: 6
    Last Post: 06-25-2003, 11:14 AM
  2. Template question
    By grscot in forum C++ Programming
    Replies: 1
    Last Post: 04-29-2003, 03:12 PM
  3. Staticly Bound Member Function Pointers
    By Polymorphic OOP in forum C++ Programming
    Replies: 29
    Last Post: 11-28-2002, 12:18 PM
  4. Using 'if' with char arrays or string objects
    By c++_n00b in forum C++ Programming
    Replies: 36
    Last Post: 06-06-2002, 09:04 PM
  5. How do I base size of arrays on annother number?
    By Dual-Catfish in forum C++ Programming
    Replies: 15
    Last Post: 09-25-2001, 01:31 PM

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