Basic problem - need help

This is a discussion on Basic problem - need help within the C Programming forums, part of the General Programming Boards category; Hi, I am really new to programming and trying to teach myself c and it's not easy! Could someone please ...

  1. #1
    Registered User
    Join Date
    Jun 2008
    Location
    Germany
    Posts
    2

    Basic problem - need help

    Hi,
    I am really new to programming and trying to teach myself c and it's not easy! Could someone please tell me why this won't work. it's not finished yet still need to add the sqrt statement. I get stuck at the average calculations.
    thanks in advance...
    jasemca


    Code:
    #include <stdio.h>
    #include <math.h>
    
    int main()
    {
        // Create two new integers to gather values
        int a = 0;
        int b = 0;
        int a+b =c;
    
        // Get me a number from the user (a)
        printf("Enter a positive whole number.\n");
        scanf("%d", &a);
        printf ("You entered %d.\n", a);
    
        // Get another number (b)
        printf("Enter a positive whole number.\n");
        scanf("%d", &b);
        printf ("You entered %d.\n", b);
    
        // Print the average
        scanf("%f",c = (a+b)/2);
        printf ("Average is: %f.\n", c);
    
        // Print another math function
       
        return 0;
    }

  2. #2
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,211
    Yeah, that's wrong. I could point out all the errors, but I think you would do best to go over your tutorials/books again.

  3. #3
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,537
    If you study your book(s)/tutorial(s) carefully, I'm sure you'll find the errors.
    You are thinking too much math and too little computer/C.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  4. #4
    Registered User
    Join Date
    Jun 2008
    Location
    Germany
    Posts
    2

    thanks

    Ok guys, thanks....I think! :-)

  5. #5
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Quote Originally Posted by jasemca View Post
    Hi,
    I am really new to programming and trying to teach myself c and it's not easy! Could someone please tell me why this won't work. it's not finished yet still need to add the sqrt statement. I get stuck at the average calculations.
    thanks in advance...
    jasemca


    Code:
    #include <stdio.h>
    #include <math.h>
    
    int main()
    {
        // Create two new integers to gather values
        int a = 0;
        int b = 0;
           int a+b =c;   //not allowed and not needed  
       //just float c will do fine
    
        // Get me a number from the user (a)
        printf("Enter a positive whole number.\n");
        scanf("%d", &a);
        printf ("You entered %d.\n", a);
        //to get  rid of the newline char still in the input buffer, you may use:
        getchar();     
    
        // Get another number (b)
        printf("Enter a positive whole number.\n");
        scanf("%d", &b);
        printf ("You entered %d.\n", b);
    
        // Print the average
        scanf("%f",c = (a+b)/2);  //this line is unnecessary
       //or c = (a+b)/2; 
       printf("Average is: %f.\n", c);
       printf ("Average is: %f.\n", (a+b/2);
       
        // Print another math function
       
        return 0;
    }
    Revisions are in red. These are very basic concepts in C. If you don't have a good book, get one. If you have one, you should study it more.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. [ANN] New script engine (Basic sintax)
    By MKTMK in forum C++ Programming
    Replies: 1
    Last Post: 11-01-2005, 09:28 AM
  2. what are your thoughts on visual basic?
    By orion- in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 09-22-2005, 04:28 AM
  3. Problem with basic encryption program.
    By mmongoose in forum C++ Programming
    Replies: 5
    Last Post: 08-27-2005, 04:41 AM
  4. Bin packing problem....
    By 81N4RY_DR460N in forum C++ Programming
    Replies: 0
    Last Post: 08-01-2005, 05:20 AM
  5. Words and lines count problem
    By emo in forum C Programming
    Replies: 1
    Last Post: 07-12-2005, 03:36 PM

Tags for this Thread


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