beginner : help

This is a discussion on beginner : help within the C Programming forums, part of the General Programming Boards category; hi i have been doing a few tutorials teaching my self c, i have tried to experiment with one of ...

  1. #1
    Registered User
    Join Date
    Feb 2009
    Posts
    2

    beginner : help

    hi
    i have been doing a few tutorials teaching my self c, i have tried to experiment with one of the exercises i have done but the out come isnt what i want. this is my source code:

    Code:
    #include <stdio.h>
    
     main ()
    
    {
          int total; 
          int a,b;
        
        printf("enter number:" ,&a);
        scanf("%d");
        printf("enter 2nd number:" ,&b);
        scanf("%d");
       
        
        total = a + b;
    
         printf(" the number is %d " ,total );
         
    getchar();
    return 0;
    }
    i want the the program so i can enter 2 numbers and it to display the sum of those two numbers. what is hapenning when i execute the program tho is, i can enter the two numbers but after that, the cmd prompt screen disappears.

    can any one help me??

    also any good links to web sites with more exercise to do wud be appreciated

    thanks
    munch114

  2. #2
    Registered User
    Join Date
    May 2008
    Posts
    25

  3. #3
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    You know what they say about horseshoes and handgrenades??? Well it usually won't apply with C (even worse: sometimes it does).

    But good try. You have something backward, I don't know what you were thinking but this is what should be:
    Code:
       printf("enter number:");
       scanf("%d",&a);
       printf("enter 2nd number:");
       scanf("%d",&b);
    See the difference?
    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

  4. #4
    Registered User
    Join Date
    Feb 2009
    Posts
    2

    reply

    lol thanks, i feel like a ryt idiot now hahahaha

    cheers 4 the help
    munch114

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Same old beginner question...
    By Sharmz in forum C Programming
    Replies: 15
    Last Post: 08-04-2008, 12:48 PM
  2. What are some good beginner programs I shouold make?
    By oobootsy1 in forum C# Programming
    Replies: 6
    Last Post: 08-09-2005, 03:02 PM
  3. Books, Beginner, MustHave
    By Zeusbwr in forum C++ Programming
    Replies: 9
    Last Post: 10-25-2004, 06:14 PM
  4. Windows programming for beginner (Absolute beginner)
    By WDT in forum Windows Programming
    Replies: 4
    Last Post: 01-06-2004, 11:21 AM

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