Page 2 of 2 FirstFirst 12
Results 11 to 14 of 14

Thread: C++ beginner need help

  1. #11
    Join Date
    Sep 2005
    Posts
    16
    Rep Power
    0

    Default program to add two numbers tell me if this is correct in c programmig

    include <stdio.h>
    include<conio.h>
    void main ()
    }
    int num1,num2,sum;
    sum=num1+num2;
    printf("enter the first number/n");
    scanf("%d",&num1);
    printf("enter second number/n");
    scanf("%d",&num2);
    printf("the sum is, sum");
    getch();
    }

  2. #12
    Join Date
    Feb 2006
    Posts
    4,242
    Rep Power
    0

    Default

    I dont have a s/w to test it but:

    printf("the sum is, sum"); should be
    printf("the sum is %d", sum);

    I'll have to check it out still. do you see the error above?
    Last edited by Utech22; Sep 26, 2008 at 06:33 AM. Reason: correction
    |--- www.RealJamaicaEstate.com ™ ---|
    Invest small = small returns [micro enterprise] | Invest Big = returns Big [macro enterprise]
    --- www.fashionsJAMAICA.com ™ -|- www.ChampsJamaica.com

  3. #13
    Join Date
    Oct 2005
    Posts
    745
    Rep Power
    0

    Default

    Quote Originally Posted by Utech22 View Post
    I dont have a s/w to test it but:

    PHP Code:
    printf("the sum is, sum"); should be
    printf
    ("the sum is %d"sum); 
    I'll have to check it out still. do you see the error above?
    Fixed .
    3.14159265358979323846264338327950288
    4197169399375105820974944592307816406
    28620899862803482534211706798 pi 101

  4. #14
    Join Date
    Apr 2008
    Posts
    5
    Rep Power
    0

    Default

    1st of all u r mixin c++ with c libraries which is wrong, if u r using c u use stdio.h if u use c++ u use iostream. This is C code below

    #include <stdio.h>
    #include <conio.h>

    void main (void)
    {
    int n = 0, m = 0;
    float total = 0.00;
    scanf("%d", &m);
    scanf("%d", &n);
    total = n+m;
    printf("%d",total/2);
    getch();
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •